freq_word/_files/cli.py
2024-09-10 15:09:19 +08:00

45 lines
1.8 KiB
Python

import os
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)
# 示例Flag
flag = os.getenv("GZCTF_FLAG", "Woodpecker{test-Flag_0}")
cipher_text = generate_substitution_cipher(flag)
print(cipher_text)