# Baby Encryption

```python
chall.py
import string
from secret import MSG

def encryption(msg):
    ct = []
    for char in msg:
        ct.append((123 * char + 18) % 256)
    return bytes(ct)

ct = encryption(MSG)
f = open('./msg.enc','w')
f.write(ct.hex())
f.close()
```

so basicly this challenge uses the encryption

```
ct.append((123 * char + 18) % 256)
```

we can reverse the process by

(123^-1 mod 256 \* (char - 18)) mod 256

```python
def decryption(c):
    m = ""
    inv = pow(123, -1, 256)
    for char in c:
        hehe = (inv * (char - 18)) % 256
        m += (chr(hehe))
    return m

with open('msg.enc', 'r') as a:
    text = bytes.fromhex(a.readline())
    print(decryption(text))
```

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FvwIZLYDBS1V19HpdJhj7%2Fimage.png?alt=media&#x26;token=d23675c7-5131-44b9-ba95-9777b687e6bd" alt=""><figcaption></figcaption></figure>
