Introduction to Cryptography

Interactive demonstrations of cryptographic principles

Diffie-Hellman Key Exchange Demo

The Diffie-Hellman key exchange is a method of generating the same pseudorandom number in two or more places without broadcasting sufficient information to replicate the process. Whenever you visit a page using HTTPS, your browser and the server use the Diffie-Hellman algorithm to generate a shared key.

How To Use This Page

Choose values for a, b, g and p, or keep the default values.

Calculate ga mod p and gb mod p and send the result to the other actor.

Calculate Ba mod p or Ab mod p without sending the result to the other actor.

Alice's Private Numbers

- Alice's secret number (a)
- Shared secret

Alice and Bob's Public Numbers

- Base (g)
- Modulo (p)
- Alice's public number (A)
- Bob's public number (B)

Bob's Private Numbers

- Bob's secret number (b)
- Shared secret

Alice
Bob

Even though an eavesdropper may know all the numbers that are transmitted between the two actors (g, p, ga mod p and ga mod p), they cannot use these numbers to calculate gab mod p. For more information on the finite fields , click here.