Mapna CTF
Crytography/What next?
Challenge Description:
In this task, we explore the realm of cryptographically secure random generators, where predicting the next output is deemed impossible. Are you ready to test your luck and skill?
Provided Files:
Solution: The output.txt
file provides the values of TMP
, KEY
, and enc
.
The what_next.py
is a program that generates a key (KEY
), encrypts the flag with this key.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python3
from random import *
from Crypto.Util.number import *
from flag import flag
def encrypt(msg, KEY):
m = bytes_to_long(msg)
c = KEY ^ m
return c
n = 80
TMP = [getrandbits(256) * _ ** 2 for _ in range(n)]
KEY = sum([getrandbits(256 >> _) for _ in range(8)])
enc = encrypt(flag, KEY)
print(f'TMP = {TMP}')
print(f'KEY = {KEY}')
print(f'enc = {enc}')
The encryption function is a simple XOR operation, Therefore, the decryption function is also an XOR operation with the same key.
1
2
3
4
5
6
7
8
9
10
11
12
from Crypto.Util.number import long_to_bytes
def decrypt(enc, KEY):
m = enc ^ KEY
msg = long_to_bytes(m)
return msg
enc = 2290064970177041546889165766737348623235283630135906565145883208626788551598431732
KEY = 23226475334448992634882677537728533150528705952262010830460862502359965393545
flag = decrypt(enc, KEY)
print(f'flag = {flag}')
Flag:
MAPNA{R_U_MT19937_PRNG_Predictor?}
This post is licensed under CC BY 4.0 by the author.