PPolySim OS

Diffie-Hellman Key Exchange

How do two people agree on a secret while a spy listens to everything they say? Diffie-Hellman — the breakthrough that made public-key cryptography possible.

Diffie-Hellman Key ExchangeLive
Alice
secret a = 6
sends A = g^a = 8
key = B^a = 2
Bob
secret b = 15
sends B = g^b = 19
key = A^b = 2
Eavesdropper sees g=5, p=23, A=8, B=19 — but cannot find the key 2

Controls

Presets

Diffie-Hellman lets two strangers agree on a secret key while an eavesdropper hears everything. Both share public numbers g and p, each picks a private exponent, and they exchange g raised to it. Raising the other's public value to your own secret yields the same shared key — yet recovering it from the public traffic requires solving the discrete logarithm, which is infeasible.

▶ Run in Python

Data Inspector

Alice sends A8
Bob sends B19
Shared secret2
Match?yes ✓

Governing equation

Reading this result: Both sides arrive at the same key 2 because (g^a)^b and (g^b)^a are the same value mod 23 — yet an eavesdropper who sees g, p, A and B must still solve a discrete logarithm to recover it.

Runs locally in your browser — free forever. Scale to the cloud when reality gets heavy.

or unlock everything with Pro →
★ Sign in to save this setup
Save your tuned setup, or drop this simulation into your own site, docs, or course page.

How it works

Both parties share public numbers, each keeps a private exponent, and they swap the generator raised to those secrets. Raising the other's public value to your own private exponent gives an identical shared key. An eavesdropper sees all the public values but would need to solve the discrete-logarithm problem to recover the key — computationally infeasible.

Ask the AI about this model

The math, the assumptions, real-world uses, or a code translation — explained for this exact simulation.

More Cryptography simulations

Frequently asked questions

Is this Diffie-Hellman key exchange tool really free?
Yes. Diffie-Hellman Key Exchange runs entirely in your browser using your device's own compute, so local use is free forever. You only pay Compute Tokens if you scale a job to the cloud.
Do I need to install anything?
No. Everything runs client-side in a modern browser — no downloads, no license, no account required to start.
Can I save or share my simulation?
Create a free account to save projects, and use a shareable embed or minted DOI to publish a live, interactive version anywhere.
How accurate are the results?
The solver uses established numerical methods, but results are for research and educational purposes and should be validated against experiment or professional review before you rely on them.