> For the complete documentation index, see [llms.txt](https://docs.cooku222.kr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cooku222.kr/security/crypto/dreamhack/dreamhack-rot128.md).

# \[DreamHack] ROT128

#### 문제 링크

{% embed url="<https://dreamhack.io/wargame/challenges/852>" %}

&#x20;

#### 문제

<figure><img src="https://blog.kakaocdn.net/dna/tb2aQ/btsNhmahUk4/AAAAAAAAAAAAAAAAAAAAALPrD1FMs4s_0J4wEP7CC4o4qgCOG1qfi2OgWSEGkFVG/img.png?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=%2B28xW2MjYNh20HraV%2FRcAa8ujPc%3D" alt="" height="385" width="1102"><figcaption></figcaption></figure>

&#x20;

#### WriteUp

```
#!/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)
```

-> rot128.py

&#x20;

```
# 0부터 255까지의 숫자를 16진수로 표현한 문자열 리스트를 생성합니다.
hex_list = [hex(i)[2:].zfill(2).upper() for i in range(256)]
print(hex_list)

# 'encfile' 파일을 UTF-8 인코딩으로 읽기 모드로 열고 내용을 'enc_s'에 저장합니다.
with open('encfile', 'r', encoding='utf-8') as f:
    enc_s = f.read()

# 'enc_s'의 내용을 두 글자씩 끊어 리스트로 만듭니다.
enc_list = [enc_s[i:i+2] for i in range(0, len(enc_s), 2)]

# 디코딩된 인덱스를 저장할 리스트 'dec_list'를 생성합니다.
dec_list = list(range(len(enc_list)))

# 'enc_list'의 각 요소에 대해 반복합니다.
for i in range(len(enc_list)):
    # 현재 두 글자 문자열의 인덱스를 'hex_list'에서 찾습니다.
    index = hex_list.index(enc_list[i])

    # 인덱스를 128을 빼고 리스트 길이로 나눠 디코딩합니다.
    dec_list[i] = hex_list[(index - 128) % len(hex_list)]

# 디코딩된 인덱스 리스트를 16진수로 변환하여 바이트 객체로 만듭니다.
dec_s = bytes(int(dec_list[i], 16) for i in range(len(dec_list)))

# 바이너리 쓰기 모드로 'decfile.png' 파일을 열고 바이트 객체를 씁니다.
with open('decfile.png', 'wb') as f:
    f.write(dec_s)
```

-> 복호화 코드

<figure><img src="https://blog.kakaocdn.net/dna/dZf9fv/btsNf9C29yC/AAAAAAAAAAAAAAAAAAAAABCfEXDUOaBMc0KZYthLY8JyU9ZVTsr8brPlcDiBzIed/img.png?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=vsuDG0z%2BFzpb2T0RJH4dg29I%2FKw%3D" alt="" height="473" width="1066"><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cooku222.kr/security/crypto/dreamhack/dreamhack-rot128.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
