import os from fastapi import FastAPI from fastapi.responses import HTMLResponse app = FastAPI() def generate_substitution_cipher(flag): substitution_rules = [] for i, char in enumerate(flag): position = i + 1 # 1-based index if char.isalpha(): if char.isupper(): substitution_rules.append(f"the {position}th flag is '{char}', upper.\n") else: # char is lowercase substitution_rules.append(f"the {position}th flag is '{char}', lower.\n") else: substitution_rules.append(f"the {position}th flag is '{char}', character.\n") substitution_dict = { 'a': 'x', 'b': 'y', 'c': 'z', 'd': 'a', 'e': 'b', 'f': 'c', 'g': 'd', 'h': 'e', 'i': 'f', 'j': 'g', 'k': 'h', 'l': 'i', 'm': 'j', 'n': 'k', 'o': 'l', 'p': 'm', 'q': 'n', 'r': 'o', 's': 'p', 't': 'q', 'u': 'r', 'v': 's', 'w': 't', 'x': 'u', 'y': 'v', 'z': 'w', 'A': 'X', 'B': 'Y', 'C': 'Z', 'D': 'A', 'E': 'B', 'F': 'C', 'G': 'D', 'H': 'E', 'I': 'F', 'J': 'G', 'K': 'H', 'L': 'I', 'M': 'J', 'N': 'K', 'O': 'L', 'P': 'M', 'Q': 'N', 'R': 'O', 'S': 'P', 'T': 'Q', 'U': 'R', 'V': 'S', 'W': 'T', 'X': 'U', 'Y': 'V', 'Z': 'W', ' ': ' ' # 保持空格不变 } substitution_rules.append("The quick brown fox jumps a lazy dog.") encrypted_rules = [] for rule in substitution_rules: for char in rule: if char in substitution_dict: encrypted_rules.append(substitution_dict[char]) else: encrypted_rules.append(char) return ''.join(encrypted_rules) @app.get("/", response_class=HTMLResponse) async def read_root(): flag = os.getenv("GZCTF_FLAG", "Woodpecker{test-Flag_0}") cipher_text = generate_substitution_cipher(flag) return f"
{cipher_text}
" if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000)