1
2
3
4
5
6
7
8
9
10
11
12
13
| def secretKey(g,a,b,p):
print 'Alice computes', g,'^',a,'mod',p,'=', mod(g^a,p), 'and sends it to Bob'
print
print 'Bob computes', g,'^',b,'mod',p,'=', mod(g^b,p), 'and sends it to Alice'
print
print 'Then, the secret key is (',mod(g^b,p),')^',a,'mod',p,'=',mod(mod(g^b,p)^a,p),'=(',mod(g^a,p),')^',b,'mod',p
secretKey(2,292,426,541) #secretKey(g,a,b,p) such that the secret numbers are g^a mod p and g^b mod p
> Alice computes 2 ^ 292 mod 541 = 69 and sends it to Bob
Bob computes 2 ^ 426 mod 541 = 171 and sends it to Alice
Then, the secret key is ( 171 )^ 292 mod 541 = 368 =( 69 )^ 426 mod 541
|