def cipher_decrypt(ciphertext, key): assert key < 2**16, '16-bit key please' assert key >= 0, '16-bit key please' prg = MT19937(key) key_stream = generate_bytes(prg, len(ciphertext)) return xor(ciphertext, key_stream)
def analyze_password_reset_token(token): current_time = int(time.time()) for possible_seed in range(current_time - 100, current_time + 50): prg = MT19937(possible_seed) if prg.extract_number() == token: return True return False
def crack_seed(random_number): current_time = int(time.time()) for possible_seed in range(current_time - 100, current_time + 40): prg = MT19937(possible_seed) if prg.extract_number() == random_number: return possible_seed assert False, 'did not cracked the seed'
def generate_random(): a = 2 b = 10 time.sleep(random.randint(a, b)) seed = int(time.time()) prg = MT19937(seed) time.sleep(random.randint(a, b)) return seed, prg.extract_number()
def main(): prg, random_numbers = generate_randoms() untempered_numbers = np.array([untemper(i) for i in random_numbers]) cloned_prg = MT19937(123) cloned_prg.mt = untempered_numbers new_numbers = [(prg.extract_number(), cloned_prg.extract_number()) for _ in range(1000)] for i, j in new_numbers: assert i == j print("challenge 3.23 completed.")
def generate_password_reset_token(): seed = int(time.time()) prg = MT19937(seed) return prg.extract_number()
def generate_randoms(): seed = 666 prg = MT19937(seed) return prg, [prg.extract_number() for _ in range(624)]