205 words
1 minute
ROT128

ROT128#

題目是

rot128.py는 flag.png 파일을 암호화하여 encfile로 저장하는 프로그램의 소스 코드입니다. (풀이자가 프로그램을 직접 실행할 수는 없습니다.)
주어진 encfile을 복호화하여 flag 파일 내용을 알아낸 뒤, flag.png에서 플래그를 획득하세요!
플래그의 형식은 DH{…} 입니다.

rot128.py

#!/usr/bin/env python3
hex_list = [(hex(i)[2:].zfill(2).upper()) for i in range(256)]
with open('flag.png', 'rb') as f:
plain_s = f.read()
plain_list = [hex(i)[2:].zfill(2).upper() for i in plain_s]
enc_list = list(range(len(plain_list)))
for i in range(len(plain_list)):
hex_b = plain_list[i]
index = hex_list.index(hex_b)
enc_list[i] = hex_list[(index + 128) % len(hex_list)]
enc_list = ''.join(enc_list)
with open('encfile', 'w', encoding='utf-8') as f:
f.write(enc_list)

script

hex_list = [(hex(i)[2:].zfill(2).upper()) for i in range(256)]
with open('encfile', 'rb') as f:
data = f.read()
data = data.decode('utf-8')
dec_list = []
def decrypt(data):
for i in range(0, len(data), 2):
hex_val = data[i:i+2]
index = hex_list.index(hex_val)
dec_list.append(hex_list[(index - 128) % len(hex_list)])
return bytes([int(i, 16) for i in dec_list])
print(decrypt(data))
with open('decfile.png', 'wb') as f:
f.write(decrypt(data))

flag

DH{y0u_So1ved_basic_cryp7o_How_wa5_1t?}