defsecretKey(g,a,b,p):print'Alice computes',g,'^',a,'mod',p,'=',mod(g^a,p),'and sends it to Bob'printprint'Bob computes',g,'^',b,'mod',p,'=',mod(g^b,p),'and sends it to Alice'printprint'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