Diffie-Hellman Key Exchange
Run a textbook Diffie-Hellman exchange with BigInt modular exponentiation.
What this page computes
Enter a prime p, a generator g and one private key per side, and the page computes A = g^a mod p, B = g^b mod p and the shared value B^a = A^b mod p using BigInt modular exponentiation. Both routes are compared and the answer says whether they agree.
Where it stops
The defaults 23, 5, 6 and 15 are the classic textbook example and are far too small to be secure, which the answer states every time. A modulus below 3, a generator outside 2…p−1 and a private key outside 1…p−2 are refused rather than quietly reduced.
Why the answer repeats
The exponentiation is integer arithmetic in this tab: no key pair is generated, no value is stored, and no exchange happens over a network. The same numbers always print the same secret.
A textbook Diffie-Hellman exchange in BigInt: A = g^a mod p, B = g^b mod p and shared = B^a = A^b mod p, with both routes compared. The defaults are the classic p = 23, g = 5 example and are not secure; every bound is refused, not clamped.
How to use it
Set p, g and both private keys, then press Run. The first two lines are the public values and the third is the shared secret with an agreement check.
The arithmetic
The shared value is g^(a·b) mod p, reachable from either side because exponentiation composes. A mismatch can only come from an input the page accepted but the group does not close over — which is why p is meant to be prime.
What to Expect
Best for
- walking through the protocol
- checking the textbook example
What this tool keeps
- both public values and the shared secret
Sample input
p 23, g 5, a 6, b 15
Sample output
Alice public A = 8 Bob public B = 19 Shared secret = 2 (both sides agree) p = 23, g = 5 — a textbook group, demonstration only, not a secure exchange.
Frequently asked questions
How do I use the diffie hellman key exchange page?
Fill in p, g and the two private keys, then press Run.
Is anything uploaded?
No. The whole calculation runs in this tab with JavaScript: no request is made, no account is needed, nothing is stored, and the page keeps working offline once it has loaded.
What are its limits or bounds?
p must be at least 3, g must be from 2 to p−1 and each private key must be from 1 to p−2. The default group is a teaching example and must not be treated as secure.
Build custom tools for your store
Join the SDK program to create useful ecommerce utilities for your store.