# Crypto challenge - Wiki Mersenne

Numpy uses plain old implementation of Mersenne Twister as the default pseudo random number generation.
Now Mersenne Twister by itself is not so bad, what’s bad is actually the seed initialization ( i.e. deriving the initial state of the random number generator from the seed ) same as explained in the Wikipedia Implementation which has been replaced in Improved Initialization with a more non-linear initialization with an array of seeds.
So, given a few (very few actually) outputs from the numpy random RNG, can you recover the flag?

Note that the seed is a 32-bit value and can be bruteforced easily, thats not the goal of this challenge, the goal of the challenge is to figure out a way which works equivalently well for MT-19937-64 bit as 64-bit is out of the bounds of bruteforce for a reasonably practical CTFer :P

import os
from numpy import random
from Crypto.Cipher import AES
from secret import flag

def rand_32():
return int.from_bytes(os.urandom(4),'big')

random.seed(rand_32())
iv,key = random.bytes(16), random.bytes(16)
cipher = AES.new(key,iv=iv,mode=AES.MODE_CBC)
flag = iv+cipher.encrypt(flag)

print(flag.hex())

# output