Rating:

# Bad Encryption
**100 points**
```
I was making an encryption program, but it is far from perfect.
Instead of make the encryption work, I decided to just encrypt everything 100 times.
```

The first step is to rename all the variables for readability with `Pycharm`(Any modern IDE would work).

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

The script seems to encode the input string(`"REDACTED"`) as a PNG image.
One can assume that instead of the hardcoded string `"REDACTED"`, the flag has been processed in the script to generate the attached 100 images.

**For each character/pixel...**
- The red and green are randomly generated.
- The blue is calculated with the following formula
```
blue = round(character * (red/256) * (green/256) * 10)
```

The idea seems to be that I need to figure out the original character by reversing the formula.

Now to look at the properties of the encryption,
- Although 100 images are generated, each image is independent.
- Blue values over 255 are capped to 255. (This took me a while to realize)
- The `round` function introduces uncertainty making it impossible to create the inverse.
```
y = round(x)
y-0.5≦x

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