DreamHack [crypto] ROT128

2023. 8. 31. 02:00Wargame/dreamhack

320x100
320x100

암호학 워게임입니다.

(암호학 최고!!!)

문제 화면

소스코드

#!/usr/bin/env python3

hex_list = [(hex(i)[2:].zfill(2).upper()) for i in range(256)]  #0~255 정수 값을 16진수 문자열로 변환한 뒤, 이를 두 자리로 맞추고 대문자로 바꾼 값을 list에 저장

with open('flag.png', 'rb') as f:  #flag파일을 이진모드로 열어서 파일 내용을 읽어옴
    plain_s = f.read()  #plain_s에 저장

plain_list = [hex(i)[2:].zfill(2).upper() for i in plain_s]  #plain_s에 저장된 바이트 값을 16진수 문자열로 변환한 뒤, 이를 두 자리로 맞추고 대문자로 바꾼 값을 list에 저장

enc_list = list(range(len(plain_list)))  #plain_list에 해당하는 범위 내에서 숫자 리스트를 생성

for i in range(len(plain_list)):
    hex_b = plain_list[i]  #plain_list에 있는 16진수 문자열
    index = hex_list.index(hex_b)  #hex_b가 hex_list에서 어느 위치에 있는지
    enc_list[i] = hex_list[(index + 128) % len(hex_list)]  #hex_list에서 hex_b의 인덱스에 128을 더한 값의 16진수 형태를 저장

enc_list = ''.join(enc_list)  #enc_list에 저장된 숫자를 문자열로 변환하여 합침

with open('encfile', 'w', encoding='utf-8') as f:  #쓰기 모드로 encfile 열고, utf-8형식으로 인코딩하여 f에 할당
    f.write(enc_list)  #enc_list 내용을 파일에 씀

복호화

=> 거꾸로

=> 로꾸거

hex_list = [(hex(i)[2:].zfill(2).upper()) for i in range(256)]

with open('encfile', 'r', encoding='utf-8') as f:
    enc_list = f.read()

enc_list = [enc_list[i:i+2] for i in range(0, len(enc_list), 2)]

plain_list = list(range(len(enc_list)))

for i in range(len(enc_list)):
    hex_b = enc_list[i]
    index = hex_list.index(hex_b)
    plain_list[i] = hex_list[(index - 128) % len(hex_list)]

plain_s = bytes.fromhex(''.join(plain_list))

with open('flag.png', 'wb') as f:
    f.write(plain_s)

복호화 성공하면

없었던 flag,png 파일이 쨔잔~~~

 

이상.//

어렵다 어려워........ 이게 beginner라니,,,,,

320x100
320x100

'Wargame > dreamhack' 카테고리의 다른 글

DreamHack [Web] file-download-1  (0) 2023.09.19
DreamHack [crypto] Basic_Crypto 1  (0) 2023.09.04
DreamHack [web] command-injection-1  (0) 2023.08.30
DreamHack [web] cookie  (0) 2023.08.27
DreamHack [crypto] SingleByteXor  (0) 2023.08.23