> For the complete documentation index, see [llms.txt](https://writeups.ayweth20.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://writeups.ayweth20.com/2025/404ctf-2025/divers/pix2num.md).

# 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>
