swuforce
[워게임]드림핵 - Basic_Crpyto1
범호야
2025. 1. 21. 23:44

문제를 열어보니

문제에서 roman emperor's cipher이라 하였으니 시 암호로 유추해볼 수 있을 것 같다.
def decrypt_cipher(ciphertext):
words = ciphertext.split() # 암호문을 공백을 기준으로 분리하여 단어 리스트로 만듭니다.
decrypted_words = []
for word in words:
decrypted_word = ""
for char in word:
ascii_code = ord(char) # 알파벳의 아스키 코드 값을 가져옵니다.
decrypted_ascii = ascii_code - 3 # 아스키 코드 값에서 3을 뺍니다.
if decrypted_ascii < 65: # 아스키 코드 값이 65 미만인 경우
decrypted_ascii += 26 # 26을 더하여 원래 알파벳의 아스키 코드 값을 구합니다.
decrypted_char = chr(decrypted_ascii) # 아스키 코드 값을 문자로 변환하여 해독된 알파벳을 얻습니다.
decrypted_word += decrypted_char
decrypted_words.append(decrypted_word)
decrypted_text = " ".join(decrypted_words) # 해독된 단어를 공백으로 연결하여 해독된 문장을 만듭니다.
decrypted_text = decrypted_text.replace(" ", "_") # 공백을 "_"로 대체합니다.
return decrypted_text
# 암호문을 파일에서 읽어옵니다.
with open("encode.txt", "r") as file:
ciphertext = file.read()
# 암호 해독 함수를 호출하여 해독된 결과를 얻습니다.
decrypted_text = decrypt_cipher(ciphertext)
# 포맷에 맞춰 해독된 결과를 출력합니다.
output = "DH{" + decrypted_text + "} "
print(output)
이렇게 풀면 flag를 얻을 수 있다.