Tags: modular-arithmetic 

Rating:

Important part in the encryption code:

```
p[0] = ((k-10) * ord(s[a])) % 251
p[1] = (k * ord(s[a])) % 251
p[2] = ((k+10) * ord(s[a])) % 251
```

This gives:
```
p[1] - p[0] = (10 * ord(s[a])) % 251
```

Now it's just modular arithmetic:

```
ord(s[a]) = (p[1] - p[0]) * inverse(10, 251) % 251
```

Full solver code:

```
from numpy import array
from PIL import Image
from Crypto.Util.number import inverse

img = Image.open('enc.png')
image = array(img)
x, y, z = image.shape
s = [''] * x
for a in range (0, x):
for b in range (0, 1):
p = image[a, b]
tensa = p[1] - p[0] if p[1] > p[0] else 251 - p[0] + p[1]
s[a] = chr(tensa * inverse(10, 251) % 251)
print(''.join(s))
```

Output:

```
Chaos isn't a pit. Chaos is a ladder, Many who try to climb it fail, and never get to try again, the fall breaks them. And some are given a chance to climb, but they refuse. They cling to the realm, or the gods, or love ... illusions. Only the ladder is real, the climb is all there is. RaziCTF{7h3_script_1s_d4rk_4nd_full_0f_m0ds}
```