times = {}
for puzzle_size in puzzle_sizes:
    times[puzzle_size] = timedelta(0)

# number of rounds
rounds = 1

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()
times = {}
for puzzle_size in puzzle_sizes:
    times[puzzle_size] = timedelta(0)

# number of rounds
rounds = 1

for i in xrange(rounds):

    for puzzle_size in puzzle_sizes:

        print "### Protocol v2 attack simulation / %s puzzles (Round %s)\n" % (puzzle_size, i)

        # Alice puzzles generation
        a = UserPuzzle(puzzle_size)
        start_time = datetime.now()
        alice_pre_puzzle_keys, alice_enc_secret_keys = a.gen_puzzles_v2()
        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()
        bob_key, bob_index = b.solve_random_puzzle_v2(alice_pre_puzzle_keys, alice_enc_secret_keys)
        bob_time = datetime.now() - start_time

        start_time = datetime.now()

        # Eve pre compute all puzzle keys
        puzzle_keys = []
        for ppk in alice_pre_puzzle_keys:
# TP Authentification : Puzzles Cryptographiques
# Sujet : http://www.irisa.fr/prive/sgambs/tp2_authentification.rtf
######################################################################
from crypto_puzzles import UserPuzzle, Puzzle
from binascii import hexlify
from datetime import datetime

puzzle_sizes = [100, 1000, 10000]

print "----" * 20

for puzzle_size in puzzle_sizes:

    print "### Protocol simulation with %s puzzles ###\n" % puzzle_size
    # Alice puzzles generation
    a = UserPuzzle(puzzle_size)
    start_time = datetime.now()
    alice_pre_puzzle_keys, alice_enc_secret_keys = a.gen_puzzles_v2()
    alice_time = datetime.now() - start_time

    # Bob receive puzzles generated by Alice
    b = UserPuzzle(puzzle_size)

    # Bob solve a random puzzle in the list
    start_time = datetime.now()
    bob_key, bob_index = b.solve_random_puzzle_v2(alice_pre_puzzle_keys, alice_enc_secret_keys)
    bob_time = datetime.now() - start_time

    # Bob now has the secret key and can send the puzzle index to
    # Alice in order that she knows which one has been choysen
    print "Key   :\t\t%s" % hexlify(bob_key)