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.

About these ads

Pages: 1 2

3 Responses to “Diffie Hellman Key Exchange”

  1. Valentin said

    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”.

  2. programmingpraxis said

    Fixed. Thanks.

  3. JP said

    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. :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 600 other followers

%d bloggers like this: