>>> ================================ RESTART ================================
# =============================
# primes and the DH protocol
# =============================
>>> p = find_prime(10)
>>> p
953
>>> len(bin(p)[2:])
10
# now that we have a way of drawing primes,
# we can execute the DH protocol
>>> g,a,b,x,y,key = DH_exchange(p)
>>> key
503
# verify computations
>>> pow(pow(g,a,p),b,p)
503
>>> pow(pow(g,b,p),a,p)
503
# crack the protocol using brute-force divisions
>>> a_guess = crack_DH(p,g,x)
>>> a_guess
403
>>> a
403
# worked like a charm!
# what if p was larger?
# this time draw a 100-bit prime
>>> p = find_prime(100)
>>> g,a,b,x,y,key = DH_exchange(p)
>>> a_guess = crack_DH(p,g,x)
100000
200000
300000
400000
500000
600000
700000
800000
Traceback (most recent call last):
File "", line 1, in
a_guess = crack_DH(p,g,x)
File "/Users/Yael/Google Drive/cs1001/week7/4class/_4_prime_all.py", line 61, in crack_DH
if pow(g,a,p) == x:
KeyboardInterrupt
# had to kill it; took to long.
# its takes around 1 second to go over 100,000 numbers.
# how long would it take to reach a ?
>>> p # large!
766203384824008074873727360429
>>> a # also large!
103123685617789785688176488569
>>> a//100000//60//60//24 # compute the number of days
11935611761318262232 # that's a lot of days