Diffie-Hellman Exchange Generator
Two people who have never met can agree on a shared value over a channel everyone is listening to. That still sounds impossible until you follow the arithmetic once, which is what this is for. Both sides pick a secret, send a derived value in the open, and raise what they receive to their own secret — arriving at the same number by different routes. These parameters are far too small to protect anything and are chosen so the arithmetic can be followed by hand. This is a teaching demonstration, not a security tool — real work belongs in a reviewed cryptographic library.
What this generator does
Computes each side's public value from its private secret, then has each raise the other's public value to its own secret. The two results are compared, and both are checked against the generator raised to the product of the secrets.
How to use this tool
- Choose a prime and a generator; both are public.
- Give each side a private secret.
- Read the two public values that get sent.
- Check that both sides arrive at the same shared value.
Understanding the controls
- Prime modulus
- Everything happens modulo this. It is public, and here it is tiny so the arithmetic stays followable.
- Generator
- The public base both sides raise their secrets over.
- The two secrets
- Never transmitted. Only the values derived from them are sent, and recovering a secret from one means solving a discrete logarithm.
Common use cases
- Following a Diffie-Hellman exchange step by step
- Teaching why the discrete logarithm problem matters
- Producing worked examples for a security course
- Showing what an eavesdropper does and does not learn
- Checking a key exchange implementation on small numbers
How this generator works
Each side computes the generator raised to its own secret, modulo the prime, and sends that. Receiving the other's value and raising it to its own secret gives the generator raised to both secrets — the same number from either direction, because exponents multiply. Before display the two sides' results are compared with each other and both are checked against the generator raised to the product of the secrets, computed directly.
Randomness and fairness
Nothing here is random. The prime, generator and two secrets determine the whole exchange. These parameters are far too small to protect anything and are chosen so the arithmetic can be followed by hand. This is a teaching demonstration, not a security tool — real work belongs in a reviewed cryptographic library.
For how randomness is produced across the whole site, see how Generate Random works.
Limitations and good to know
- The prime is small enough that an eavesdropper can recover a secret by brute force in moments; real exchanges use primes hundreds of digits long.
- There is no authentication, so this exchange as shown is vulnerable to an interceptor sitting in the middle — real protocols add signatures for exactly that reason.
- Not every generator generates the whole group, which changes how many distinct shared values are possible.
- This demonstrates the idea only and must not be used to protect anything real.
Privacy and your data
The exchange is computed in your browser and no value you enter is transmitted, stored or included in analytics.
Related generators
- Toy RSA Key GeneratorBuilds a tiny RSA key from two small primes and checks that every message in the modulus survives being encrypted and decrypted.
- Secret Sharing GeneratorSplits a number into shares where any threshold of them rebuilds it — checked by trying every combination — and fewer reveal nothing.
- One-Time Pad GeneratorEncrypts a message with a pad exactly as long as it, then removes the pad again and checks the plaintext came back letter for letter.
- Modular Arithmetic Question GeneratorRemainders, modular powers by repeated squaring, and inverses that only exist when the values are coprime.