Rating:

# Super Encryption!
**60 points**
```
My friend sent me a flag encrypted with an encryption program.
Unfortunately, the decryption doesn't seem to work.
Please help me decrypt this: dufhyuc>bi{{f0|;vwh<~b5p5thjq6goj}
```
![](https://gyazo.com/6446894bd88cdd6a27a5c4d772013086.png)

The decryption is not implemented in the attached file (`superencrypt`) so the inverse of the encryption has to be handcrafted.

**The entrypoint(`main`) in IDA**
![](https://gyazo.com/5f9c8326bd25bbb7cc75446627dd3461.png)

A very straight forward branch is made to `encrypt` and `decrypt` based on the user input.

![](https://gyazo.com/89ada7f09acc77d6445ba25e8b03ee0f.png)

As expected, nothing happens in the `decrypt` function.

![](https://i.gyazo.com/ccc8bcd8ff5d4e4620989b5f3aaec75a.png)

Prior to calling `encrypt`, the parameters are copied to `rsi` and `rdi` and later on copied to the stack in the function entrypoint.

![](https://gyazo.com/6fbec922fbd081dfcd3fb016b984b326.png)

`rdi` points to the given string
`rsi` holds `0x100` which is probably the buffer length

![](https://gyazo.com/eb2d18a9817ede5b76295abae145c9e3.png)

Although there are 3 loops in the function, the encryption itself is done in the first one. To be specific, a key is derived from the loop counter(`i`) and added to each character.

![](https://gyazo.com/17b63a8897d6dd55a517c2912cf4abd9.png)

The second and third loops are responsible for reversing the order of the cipher in chunks of 5 and 3 respectively.

The following steps need to be taken for decryption.
1. Reverse order by chunks of 3
2. Reverse order by chunks of 5
3. Derive key from loop counter and subtract from each character

One thing to note is that instead of deriving the key myself, I ripped the key by logging the values stored in `v13`(`xmm0`).

Original writeup (https://github.com/k8tems/ctf_writeups/tree/master/2017-12-04%20Tahoma%20Park%20CTF/Super%20Encryption!).