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