Diffie-Hellman Key Calculator
Enter the public parameters and both private keys to derive the shared secret.
How it is calculated
You supply the public prime p, the generator g and two private exponents a (Alice) and b (Bob). The tool computes each public value by fast modular exponentiation (square-and-multiply): A = ga mod p and B = gb mod p. Then each side raises the other's public value to its own private exponent: s = Ba mod p for Alice and Ab mod p for Bob. Both must give the same number, and the page shows both so you can check. All four inputs must be whole numbers below 253, with p above 1, g above 0 and a, b not negative. The modulus p is tested for primality (Miller-Rabin); if p is not prime, a decimal is entered, or any value is out of range, the tool shows no result. Products are computed without overflow, so large primes up to about 9 quadrillion work.
Worked example
Take the textbook values p = 23, g = 5, Alice's a = 6 and Bob's b = 15. Alice's public value is 56 mod 23 = 15,625 mod 23 = 8. Bob's is 515 mod 23 = 19. Alice computes 196 mod 23 and Bob computes 815 mod 23; both arrive at the shared secret 2, and the verification line shows 2 as well. An eavesdropper sees only 23, 5, 8 and 19.
Common mistakes
- Choosing a composite modulus such as p = 24. The tool checks that p is prime and returns nothing otherwise, because the exchange is not meaningful modulo a composite number.
- Entering a decimal exponent such as 6.5, or a negative one. Only whole, non-negative private keys are accepted, so no result appears.
- Swapping the private and public values. a and b are the secret exponents; the public values A and B are outputs, not inputs.
- Picking a generator that gives a trivial exchange: g = 1 makes every public value and the shared secret equal to 1. A useful g generates many residues modulo p, so check it against p rather than choosing at random.
- Expecting real security from the result. Practical Diffie-Hellman uses primes thousands of bits long, so a calculator limited to numbers below 253 is for learning and hand-checking only.
About this calculator
The Diffie-Hellman key exchange lets two parties agree on a shared secret over a public channel without ever transmitting the secret itself. Both sides agree on a public prime modulus p and generator g; each picks a private key (a and b) and computes a public key — A = g^a mod p and B = g^b mod p — which they exchange openly. Each side then raises the other's public key to their own private key: the shared secret is s = B^a mod p = A^b mod p = g^(ab) mod p, arriving at the same number without either private key ever crossing the wire.
Security rests on the discrete logarithm problem — computing a from g, p and A = g^a mod p is computationally infeasible for a large enough prime p, even though computing A from a is easy. Computer science students, security engineers, and protocol implementers use small-number examples like this to verify by hand how TLS, SSH, and other protocols establish a shared session key before any application data is sent.
Was this helpful?
You can pick up to 3 reactions.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm’s Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
Comments