#!/usr/bin/env python # chal21.py - Implement MT19937 # # Copyright (C) 2015 Andrew J. Zimolzak <*****@*****.**>, # and licensed under GNU GPL version 3. Full notice is found in # the file 'LICENSE' in the same directory as this file. from cryptopals import warn from myrand import MTRNG r = MTRNG(12436) print r.extract_number() print r.extract_number() print r.extract_number() print r.extract_number() print r.extract_number() print r.extract_number() print r.extract_number() print r.extract_number() #### tests, if any #### warn("No errors:", __file__)
# chal22.py - MT19937 seed # # Copyright (C) 2015 Andrew J. Zimolzak <*****@*****.**>, # and licensed under GNU GPL version 3. Full notice is found in # the file 'LICENSE' in the same directory as this file. from cryptopals import warn from myrand import MTRNG, find_time_seed import time import random #### Generate a number from RNG seeded with time time.sleep(random.randint(7, 15)) # 40,1000 is more fun though r = MTRNG(int(time.time())) time.sleep(random.randint(7, 15)) target_num = r.extract_number() #### Reverse engineer the seed print "Received target of:", target_num found_seed = find_time_seed(target_num, int(time.time())) print "Seed used was:", found_seed print "In other words,", time.ctime(found_seed) #### tests, if any #### assert (found_seed > 1441224144) warn("Passed assertions:", __file__)
output = input ^ ((output << k) & mask) bits += k return output def untemper(y4): y3 = untemper_partial(y4, l, "right") y2 = untemper_partial(y3, t, c) y1 = untemper_partial(y2, s, b) return untemper_partial(y1, u, "right") answer = untemper(0xe016575d) print "Untemper result is:", hex(answer) rng = MTRNG(67812) state = [0] * n for i in range(n): state[i] = untemper(rng.extract_number()) clone = MTRNG(state) print "Cloning results are:" for i in range(10): x = clone.extract_number() y = rng.extract_number() print x, y assert x == y #### tests, if any ####
# chal22.py - MT19937 seed # # Copyright (C) 2015 Andrew J. Zimolzak <*****@*****.**>, # and licensed under GNU GPL version 3. Full notice is found in # the file 'LICENSE' in the same directory as this file. from cryptopals import warn from myrand import MTRNG, find_time_seed import time import random #### Generate a number from RNG seeded with time time.sleep(random.randint(7,15)) # 40,1000 is more fun though r = MTRNG(int(time.time())) time.sleep(random.randint(7,15)) target_num = r.extract_number() #### Reverse engineer the seed print "Received target of:", target_num found_seed = find_time_seed(target_num, int(time.time())) print "Seed used was:", found_seed print "In other words,", time.ctime(found_seed) #### tests, if any #### assert(found_seed > 1441224144) warn("Passed assertions:", __file__)
output = input ^ (output >> k) else: output = input ^ ((output << k) & mask) bits += k return output def untemper(y4): y3 = untemper_partial(y4, l, "right") y2 = untemper_partial(y3, t, c) y1 = untemper_partial(y2, s, b) return untemper_partial(y1, u, "right") answer = untemper(0xe016575d) print "Untemper result is:", hex(answer) rng = MTRNG(67812) state = [0] * n for i in range(n): state[i] = untemper(rng.extract_number()) clone = MTRNG(state) print "Cloning results are:" for i in range(10): x = clone.extract_number() y = rng.extract_number() print x, y assert x == y #### tests, if any ####