Tags: crypto 

Rating:

```

import decimal
from Crypto.Util.number import *
def ungantunex(x, length=6):
if len(long_to_bytes(x)) <= length:
try:
return long_to_bytes(x).decode('utf8')
except UnicodeDecodeError:
pass
x = decimal.Decimal(x)
root = int(x.sqrt(context=decimal.Context(prec=300)))
pad = int(x) - (root ** 2)
if pad > root:
pad -= root
return ungantunex(root, length), ungantunex(pad, length)
return ungantunex(pad, length), ungantunex(root, length)

f = open('flag.enc', 'rb')
print(ungantunex(bytes_to_long(f.read()), 6))
f.close()

```
after run, we got this :
```
(((('m0rE_e', '_P41RI'), 'SUSEC{'), 'ct1ON}'), ('L39An7', 'NG_fUn'))
```

with some brute force on permutations we can find the flag:
```
SUSEC{m0rE_eL39An7_P41RING_fUnct1ON}
```