> For the complete documentation index, see [llms.txt](https://digitalgarden.batamladen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://digitalgarden.batamladen.com/writeups/ctfs/0xfun-ctf-2026/crypto-leonine-misbegotten.md).

# Crypto - Leonine Misbegotten

### Challenge Summary

The challenge gives you a huge file. Looking at `chall.py`, we see that the flag is **encoded 16 times** in layers using a random choice of one of four encoding schemes:

* Base16 (`b16encode`)
* Base32 (`b32encode`)
* Base64 (`b64encode`)
* Base85 (`b85encode`)

After each encoding, the program **appends the SHA-1 hash of the data before encoding**.

The `output.txt` file is therefore:

```
ENCODED_DATA + SHA1
ENCODED_DATA + SHA1
...
```

And the goal is to recover the original flag.

***

### Solve.py

```python
from base64 import b16decode, b32decode, b64decode, b85decode
from hashlib import sha1

SCHEMES = [b16decode, b32decode, b64decode, b85decode]

with open("output", "rb") as f:
    data = f.read()

for round in range(16):
    new_data = None
    checksum = data[-20:]  # SHA-1 is 20 bytes
    candidate = data[:-20]

    for dec in SCHEMES:
        try:
            decoded = dec(candidate)
            if sha1(decoded).digest() == checksum:
                new_data = decoded
                break
        except Exception:
            pass

    if new_data is None:
        raise Exception("Failed at round", round)

    data = new_data

print(data.decode())

```

Flag:\
`0xfun{p33l1ng_l4y3rs_l1k3_an_0n10n}`


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://digitalgarden.batamladen.com/writeups/ctfs/0xfun-ctf-2026/crypto-leonine-misbegotten.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
