# AES-ABC

## Problem

> AES-ECB is bad, so I rolled my own cipher block chaining mechanism - Addition Block Chaining! You can find the source here: aes-abc.py. The AES-ABC flag is body.enc.ppm

* [Source](https://github.com/HHousen/PicoCTF-2019/tree/24b0981c72638c12f9a8572f81e1abbcf8de306d/Cryptography/AES-ABC/aes-abc.py)
* [Source](https://github.com/HHousen/PicoCTF-2019/tree/24b0981c72638c12f9a8572f81e1abbcf8de306d/Cryptography/AES-ABC/body.enc.ppm)

## Solution

1. Header is the first three lines of `body.enc.ppm` so save those.
2. For the actual picture info extract from bytes to ints in blocks of 16 since that is what the [encryption script](https://github.com/HHousen/PicoCTF-2019/tree/24b0981c72638c12f9a8572f81e1abbcf8de306d/Cryptography/AES-ABC/aes-abc.py) does.
3. The [encryption script](https://github.com/HHousen/PicoCTF-2019/tree/24b0981c72638c12f9a8572f81e1abbcf8de306d/Cryptography/AES-ABC/aes-abc.py) encodes blocks by doing `(previous block + current block) % UMAX` so the [decryption script](https://github.com/HHousen/PicoCTF-2019/tree/24b0981c72638c12f9a8572f81e1abbcf8de306d/Cryptography/AES-ABC/script.py) does the opposite: `(current - previous) % UMAX`.
4. Run that for each block and convert back to bytes.
5. Copy the file header to a new image and append each block to that image.
6. See [ebc.png](https://github.com/HHousen/PicoCTF-2019/tree/24b0981c72638c12f9a8572f81e1abbcf8de306d/Cryptography/AES-ABC/ebc.png) for example on why we don't bother decrypting ebc. More info at [Wikipedia](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation)

### Flag

`picoCTF{d0Nt_r0ll_yoUr_0wN_aES}`


---

# 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://picoctf2019.haydenhousen.com/cryptography/aes-abc.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.
