for i in xrange(rounds): for puzzle_size in puzzle_sizes: print "### Protocol v1 attack simulation / %s puzzles (Round %s)\n" % (puzzle_size,i) # Alice puzzles generation a = UserPuzzle(puzzle_size) start_time = datetime.now() alice_puzzles = a.gen_puzzles_v1() alice_time = datetime.now() - start_time # Bob receive puzzles generated by Alice and solve a random puzzle in the list b = UserPuzzle(puzzle_size) start_time = datetime.now() key, index = b.solve_random_puzzle(alice_puzzles) bob_time = datetime.now() - start_time # Eve try to solve all puzzles until the key found matches bob's key start_time = datetime.now() for ppk,enc_sk in alice_puzzles: p = Puzzle(None,ppk,enc_sk) eve_key,eve_index = p.solve_puzzle() if eve_key == key: print "Key :\t\t%s" % hexlify(eve_key) print "Index:\t\t%d" % eve_index eve_time = datetime.now() - start_time times[puzzle_size] += eve_time print "\nAlice time :\t%s" % alice_time