/* from http://www.linuxjournal.com/article.php?sid=6131 */ /* run `bc < DiffieHellmanWithDB.txt` */ q = 563 /* Alice and Bob select a large prime */ a = 5 /* ...and another random number */ xa = 9 /* Alice picks the random number 9 */ xb = 14 /* Bob picks the random number 14 */ ya = a ^ xa /* Alice */ ya = ya % q print "\nAlice sends ya = ", ya," to Bob\n"; yb = a ^ xb /* Bob */ yb = yb % q print "Bob sends yb = ", yb," to Alice\n"; ka = yb ^ xa print "\n from yb^xa = ";ka; ka = ka % q print " Alice calculates ka = ",ka,"\n" kb = ya ^ xb print " from ya^xb = "; kb; kb = kb % q print " Bob calculates kb = ",kb,"\n"; print "\nThey can now use ",kb," to encrypt messages.\n"; quit