Diffie Hellman Key Exchange
September 12, 2013
There isn’t really any programming to do; the only thing we need is a function that performs modular exponentiation, which is provided as expm
in the Standard Prelude. Thus:
> (expm 5 6 23)
8
> (expm 5 15 23)
19
> (expm 19 6 23)
2
> (expm 8 15 23)
2
You can run the program at http://programmingpraxis.codepad.org/jofMLjUD.
Typo: … choosing b, computing gb (mod p), and sending it to Alice; in a real application, a will be…
The last “a” should be a “b”.
Fixed. Thanks.
Here’s mine in Racket: jverkamp.com: Diffie-Hellman Key Exchange
I half used it as an excuse to learn about how Racket’s TCP connections work. The key exchange takes a client/server model and once the secret is established it’s used to seed the RNG for an xor encryption cipher. Works rather well and was fun to write. Racket’s math/number-theory library helped somewhat. :)