# Pix2Num

**Catégorie:** Divers - **Difficulté:** Intro

{% file src="/files/z3r3e2hu5QQ4RL7RqZl4" %}

**Description:**

<figure><img src="/files/DDEQJHEM0Dniok3n3ubX" alt=""><figcaption></figcaption></figure>

Solution:

Pour ce chall, il fallait reconstruire une image à partir d'un fichier donné (numbers.txt) et d'un script python afin de comprendre ce qu'il s'est passé avec ces nombres.

Nous allons directement développer un script afin de reconstruire l'image d'origine :&#x20;

```python
from PIL import Image
import sys
sys.set_int_max_str_digits(50000)

# Utiliser la clé déduite
key = 9140188724517997073

# Recharger le nombre chiffré
with open("number.txt") as f:
    encrypted_number = int(f.read().strip())

# Déchiffrement bloc par bloc
decrypted_number = 0
shift = 0
while encrypted_number:
    encrypted_block = encrypted_number & 0xFFFFFFFFFFFFFFFF
    decrypted_block = encrypted_block ^ key
    decrypted_number |= (decrypted_block << shift)
    encrypted_number >>= 64
    shift += 64

# Conversion du nombre en binaire, puis en pixels
binary_str = bin(decrypted_number)[2:].zfill(400 * 200)  # On connaît les dimensions
pixels = [255 if bit == '1' else 0 for bit in binary_str]

# Création de l'image
image = Image.new('L', (400, 200))
image.putdata(pixels)
image_path = "decrypted_flag.png"
image.save(image_path)

image_path
```

Cela nous reconstruit directement notre image d'origine :&#x20;

<figure><img src="/files/HE9TlT2ebBOeAZXkXgjf" alt=""><figcaption></figcaption></figure>

<details>

<summary>🚩FLAG</summary>

`404CTF{4n_a11eN_ha9_b33n_70UnD}`

</details>


---

# Agent Instructions: 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://writeups.ayweth20.com/2025/404ctf-2025/divers/pix2num.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.
