def clone_MT19937_prng(prng): return mt.MT19937(5489, [untemper(prng.extract_number()) for i in range(624)])
def unbitshift_left_xor(value, shift, mask): i = 0 result = 0 while (i * shift < 32): partMask = (0xffffffff >> (32 - shift)) << (shift * i) part = value & partMask value ^= (part << shift) & mask result += part i += 1 return np.uint32(result) def untemper(y): value = y value = unbitshift_right_xor(value, 18) value = unbitshift_left_xor(value, 15, 4022730752) value = unbitshift_left_xor(value, 7, 2636928640) value = unbitshift_right_xor(value, 11) return value def clone_MT19937_prng(prng): return mt.MT19937(5489, [untemper(prng.extract_number()) for i in range(624)]) if __name__ == "__main__": rng = mt.MT19937() clone = clone_MT19937_prng(rng) for i in range(100000): assert(rng.extract_number() == clone.extract_number())
def crack_seed(random_number): curr_time = int(time.time()) for seed in range(curr_time - 1000, curr_time): if mt.MT19937(seed).extract_number() == random_number: return seed
def get_random_number(): time.sleep(random.randint(4, 1000)) seed = int(time.time()) rng = mt.MT19937(seed) time.sleep(random.randint(4, 1000)) return {'rand': rng.extract_number(), 'seed': seed}
def get_keystream(key): rng = mt.MT19937(key) while True: yield from int(rng.extract_number()).to_bytes(4, byteorder='little')