2024-09-10 15:22:24 +08:00

52 lines
2.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 letter is '{char}', upper.\n")
else: # char is lowercase
substitution_rules.append(f"the {position}th letter is '{char}', lower.\n")
else:
substitution_rules.append(f"the {position}th letter is '{char}', character.\n")
substitution_dict = {
'a': 'z', 'b': 'i', 'c': 'j', 'd': 'r', 'e': 'd', 'f': 'u', 'g': 'a',
'h': 'e', 'i': 'n', 'j': 'o', 'k': 'm', 'l': 'f', 'm': 'k', 'n': 'l',
'o': 'v', 'p': 'q', 'q': 'x', 'r': 'y', 's': 'c', 't': 't', 'u': 'p',
'v': 'h', 'w': 's', 'x': 'w', 'y': 'b', 'z': 'g',
'A': 'Z', 'B': 'I', 'C': 'J', 'D': 'R', 'E': 'D', 'F': 'U', 'G': 'A',
'H': 'E', 'I': 'N', 'J': 'O', 'K': 'M', 'L': 'F', 'M': 'K', 'N': 'L',
'O': 'V', 'P': 'Q', 'Q': 'X', 'R': 'Y', 'S': 'C', 'T': 'T', 'U': 'P',
'V': 'H', 'W': 'S', 'X': 'W', 'Y': 'B', 'Z': 'G',
' ': ' ' # 保持空格不变
}
substitution_rules.append("Pack my box with five dozen liquor jugs.")
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"<h1>下面的密文有Flag哦PS单表替换</h1><p>{cipher_text}</p><h1>下面的内容是什么呢?</h1><p>I43XOm-hSG-WPrUURqZoO0-aOLNZ64FjSaJi64ldQLJjQW-eRKRn9iWzaSKDdSWjbSKQeCKjViOKVya5XCaRciC+UU</p>"
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)