George Lake
Diffie-Hellman in Redux a guide to the Diffie-Hellman page
Redux crypto guides · Diffie-Hellman

Diffie-Hellman: agreeing on a secret while everyone listens

Diffie-Hellman: the discrete log, two classical attacks, and Shor's algorithm

Diffie-Hellman (named after Whitfield Diffie and Martin Hellman, who published it in 1976) lets two people who have never met agree on a secret number, even though everything they say to each other can be overheard. This guide shows how it works with numbers small enough to check by hand, how an eavesdropper breaks it when the numbers are small, and why quantum computers are a big deal for it. Every example matches what you will see on the Diffie-Hellman page in Redux.

How Redux's Diffie-Hellman problem models a key exchange on toy parameters: the instance formats, the discrete logarithm behind it, two classical attacks (brute force and baby-step giant-step), why the certificate carries a private key, how to read the step table, and where Shor's algorithm enters. Every number on this page comes from the default instance (59,2,13,23,"Hello World").

Alice's message, locked with the secret she shares with Bob
Default instance: p = 59, g = 2, a = 13, b = 23, so s = 40

Top: the message. Middle: each letter as a number (A = 1, B = 2, ..., space = 27). Bottom: what actually travels, and all an eavesdropper sees.

Each symbol is encoded as m (A = 1 ... Z = 26, space = 27) and encrypted as c = m · s mod p with the shared secret s = 40.

1

Mixing paint in public

The setting: the attacker's view

Alice and Bob want to send each other secret messages, but they have never met, and Eve hears everything they say. To lock messages they need a secret number that only the two of them know. How do you agree on a secret when someone is always listening?

Think of paint. Mixing two paints is easy, but nobody can pull a mixed paint apart again. Diffie-Hellman does the same thing with numbers:

Diffie-Hellman is a key exchange, not an encryption scheme: two parties agree on a shared secret over a public channel. Redux models it from the eavesdropper's side. Eve is passive: she knows the public parameters (p, g) and both public values A = ga mod p and B = gb mod p, and wants the shared secret s = gab mod p, or the message encrypted with it.

In message mode, (p,g,a,b,"TEXT"), the instance string contains both private keys and the plaintext so that Redux can run the exchange for you; the problem keeps only p, g, A, B and the ciphertext. Note that positions 3 and 4 are private keys here, and public values in Eve's-view instances (p,g,A,B).

A B 59, 2 PUBLIC: everyone knows it 13 23 Alice's secret Bob's secret
They agree out loud on a starting paint: two numbers, 59 and 2 (section 2 shows what each one does). Each secretly picks a color of their own: Alice 13, Bob 23.Public parameters p = 59, g = 2; private keys a = 13, b = 23.
50 47 Alice's mix Bob's mix E Eve sees 59, 2, 50 and 47
Each mixes the starting paint with their secret color and sends the mix across. Eve sees both mixes, but she can't unmix them.A = 213 mod 59 = 50 and B = 223 mod 59 = 47 are sent in the clear.
47 + 13 50 + 23 Alice Bob 40 SHARED SECRET
Each adds their own secret color to the mix they received. Both end with exactly the same brown, the number 40, which never traveled at all. (With numbers, mixing means multiplying, not adding: section 2 shows how.)s = Ba mod p = Ab mod p = 213 · 23 mod 59 = 40.
2

Mixing with numbers

The exchange, and the discrete logarithm

In Diffie-Hellman, "mixing" means this: multiply together as many 2s as your secret number, divide by 59, and keep only the remainder, the amount left over. Alice's secret is 13, so she works out 2 × 2 × ... × 2 with 13 twos, which is 8,192. That is 138 × 59 with 50 left over, so Alice sends 50.

59 is a prime number: it divides evenly only by 1 and itself. That matters for the math, but you don't need the details here.

Change the secret numbers below and watch both of them land on the same shared secret.

Public: a prime p and a generator g of the multiplicative group mod p (here 2 has order 58 = p − 1, so its powers run through every value 1 ... 58). Alice picks a, sends A = ga mod p; Bob picks b, sends B = gb mod p. Both compute s = gab: Alice as Ba, Bob as Ab.

Recovering a from (p, g, A) is the discrete logarithm problem (DLP). Computing gab from ga and gb is the computational Diffie-Hellman problem (CDH); solving the DLP solves CDH, and no better route is known for well-chosen groups.

Alice

She sendsA = g^a mod p
She mixes Bob's number with her secrets = B^a mod p

Out in the openPublic channel

Agreed numbersp, g59, 2
Alice's mix →A →
← Bob's mix← B
Eve hears all of thisEve's view: (p, g, A, B)

Bob

He sendsB = g^b mod p
He mixes Alice's number with his secrets = A^b mod p

Alice gets the shared secret the same way she made her mix: she multiplies 13 copies of Bob's 47 together and keeps the remainder after dividing by 59. Bob does the same with 23 copies of Alice's 50. Secret numbers go from 1 to 57: 58 twos leave a remainder of 1 again, and after that the remainders repeat, so bigger secrets add nothing. Tip for checking by hand: take the remainder after every multiplication, and the numbers stay small.

Private keys 1 ≤ a, b ≤ p − 2, as Redux's instance check requires.

Why do they both get the same number? Alice's mix is made of 13 twos, and Bob multiplies 23 copies of it together. Bob's mix is made of 23 twos, and Alice multiplies 13 copies of it together. Either way the result is 13 × 23 = 299 twos multiplied together, so both remainders are the same: 40. And taking the remainder along the way, as Alice and Bob do, never changes the final remainder, so working with 47 instead of the huge number gives the same answer.

3

Locking a message with the shared secret

Encrypting with s (ElGamal style)

Now Alice and Bob share the secret 40, and Eve doesn't. Alice turns each letter into a number (A = 1, B = 2, ..., Z = 26, space = 27), multiplies it by 40, divides by 59 and sends the remainder. H is 8; 8 × 40 = 320, which is 5 × 59 with 25 left over, so H is sent as 25.

To unlock, Bob multiplies by 31 instead and keeps the remainder after dividing by 59. Why 31? Bob finds it by trying 40 × 1, 40 × 2, 40 × 3, ... until the remainder is 1: 40 × 31 = 1,240, which is 21 × 59 with 1 left over. That means multiplying by 31 undoes multiplying by 40. So 25 × 31 = 775, which is 13 × 59 with 8 left over: H again.

Type your own message below to see each letter locked.

Message mode encrypts each symbol as c = m · s mod p and decrypts with m = c · s−1 mod p, where s−1 = 31 (40 · 31 = 1240 = 21 · 59 + 1). Codes must stay below p, so message mode requires p > 27.

Instance checks: p ≥ 3, 1 < g < p; in Eve's view 1 ≤ A, B ≤ p − 1; in message mode 1 ≤ a, b ≤ p − 2 and only letters and spaces (lower case is accepted; the answer comes back in upper case). Whether p is prime and g a generator is not checked up front: the attacks find out, as an attacker would (section 9).

This is a teaching cipher, not real ElGamal. One fixed s for every symbol makes this a substitution cipher on 28 symbols: equal letters give equal ciphertexts (the three L's in HELLO WORLD are all 8). Real ElGamal uses a fresh random exponent for every message, and real protocols (TLS, SSH, Signal) feed s into a key-derivation function and encrypt with a symmetric cipher such as AES. Redux keeps the per-symbol version because every step is visible and checkable by hand.

4

How Eve tries to unmix the paint

Attack 1: brute-force discrete log (DH Brute Force Discrete Log)

Eve knows the starting number 2, the prime 59, and Alice's mix, 50. If she can find out how many twos went into 50, she has Alice's secret, and then she can do exactly what Alice did to get the shared secret 40.

The simplest way: list the remainders of 2, 2 × 2, 2 × 2 × 2, and so on, one more two each time, until she reaches 50. Each new remainder is just the previous one doubled (taking off 59 if it goes past). Below, the list is laid out 8 to a row, so the square in row 1, column 5 is the one with 1 × 8 + 5 = 13 twos. The big number in each square is the remainder; the small one in the corner (on wider screens) counts the twos. Eve starts from 1, before any twos, so 13 twos is her 14th try. Press the button to watch her search.

The default solver in Redux's problem definition. It walks x = 0, 1, 2, ... computing gx mod p by one multiplication per step until gx = A, then sets s = Bx mod p and decrypts each symbol with s−1. Up to p − 1 multiplications: linear in p, exponential in its bit length.

With Alice's secret, Eve rebuilds the shared secret and unlocks every letter. Press play to watch her notebook fill in. It is the same table Redux shows, with Redux's own explanations. A few row names are friendlier here: Redux says "public value" for a mix and "private key" for a secret number.

The step table below replays the solver's recorded steps for the default instance, with Redux's own text. Switch to baby-step giant-step to compare (section 6).

Reading Redux's shorthand. Redux writes its notebook in math shorthand. Here is what it means:

  • Letters: p is the prime (59), g the starting number (2), A and B the two mixes that are sent (50 and 47), a and b the secret numbers, s the shared secret (40), c the locked numbers, and m the message.
  • mod 59: the remainder after dividing by 59.
  • 2^13, g^a, B^a: 2^13 means 13 twos multiplied together. With letters it works the same way, using the numbers from the table: g^a is a copies of g multiplied together, so B^a with B = 47 and a = 13 is 13 copies of 47.
  • x: the number of twos Eve is trying.
  • Key: another word for a secret number. Alice's key is 13.
  • s⁻¹: the number that undoes multiplying by s. For s = 40 that is 31.
  • Public parameter means one of the agreed numbers, and ciphertext means the locked numbers.

These are Redux's names for Eve's two attacks. "Brute force" means trying every possibility in turn, which is what this section does, and "discrete log" is the math name for "how many twos went in". The second one is the shortcut in section 6.

ValueNumberCan Eve see it?Visible to the attacker?How Eve knows itHow the attacker knows it

Blue: the row Eve just worked out. Green appears when the message is found. Bob's secret stays "?": Eve never needs it.Blue is Redux's ElementHighlight (the value found in this step); green is Solution. b stays "?": one private key is enough.

5

Run it in Redux

Here is the Diffie-Hellman page in Redux, and what each part does.

The Diffie-Hellman page (/Diffie-Hellman in Redux_Frontend). The parts below map onto Redux's problem interface: the instance, the chosen solver, the chosen visualization, and the verifier.

The Diffie-Hellman page in Redux before running: details panel on the left, the instance box, solver menu and Run solve button at the top, and the attacker table below 1 2 3 4 5 6 7
  1. 1Details. The problem in words. It uses some technical terms; this guide explains the same ideas in plain words. Close it with × for more room.problemDefinition, input and output descriptions, source and contributors.
  2. 2Instance. The puzzle: the agreed numbers, Alice's and Bob's secret numbers, and the message. Press Edit to type your own.(p,g,a,b,"TEXT") or (p,g,A,B). Edit to change it; it is checked as you type.
  3. 3Solver. Which attack Eve uses. The page starts with DH Baby-Step Giant-Step (section 6) selected; choose DH Brute Force Discrete Log from this menu to follow section 4. The small tags (like NP or Brute Force) and the Reduce button are for other parts of Redux; you can ignore them.The two ISolver classes, both tagged Brute Force and Exponential. Redux_Frontend preselects the first solver by class name, DHBabyStepGiantStepSolver, rather than the problem's defaultSolver (brute force).
  4. 4Run solve. Runs the attack.Runs the solver and records its steps for the picture.
  5. 5Visualization Type. How the attack is drawn. Diffie-Hellman has one picture: the Attacker Knowledge Table.Diffie-Hellman Attacker Knowledge Table, a DynamicTable with one frame per step.
  6. 6The table. What Eve knows. Before running, only the public numbers are filled in. The last row, the message, sits just below the edge of the box: scroll the table a little to see it.Public rows p, g, A, B, c; secret rows a, b, s, m shown as "?". The table box is 400 px tall, so the m row needs a small scroll.
  7. 7Result. The answer, and a box where you can check any answer yourself.Answer (certificate), timing, and the verifier.

Checking an answer

The verifier, and why the certificate carries the key

The Result panel shows the answer and lets you check any answer you type. Redux calls a proposed answer a certificate. Here it has two parts, Alice's secret number and the message: (13,"HELLO WORLD"). Why the secret number too? Redux can't check a message on its own, because only someone who knows a secret number can make the shared secret. With Alice's secret it can: it checks that 13 twos really give 50, makes the shared secret from it, and locks your message to compare with what Eve intercepted.

The Default Diffie-Hellman Verifier checks ga mod p = A for 0 ≤ a ≤ p − 2, then computes s = Ba mod p, re-encrypts the proposed message and compares it with c. A message or a shared secret alone could not be verified from public values: deciding whether a candidate equals gab is the decisional Diffie-Hellman problem (DDH), assumed hard. The private key is an efficiently checkable witness, which is why the problem is declared in NP: Diffie-Hellman = {<p, g, A, B> | some a with 0 <= a <= p - 2 has g^a = A (mod p)}.

Result and Verify panel showing the answer (13, HELLO WORLD)
The answer after Run solve.
Checking (13, HELLO WORLD): valid certificate
(13,"HELLO WORLD"): accepted.
Checking (13, HELLO WORLE): not a valid certificate
(13,"HELLO WORLE"): rejected.
The instance (59,2,13,23,"Hi!") outlined in red, with Run solve grayed out

If Redux can't read the instance

The box turns red and Run solve is grayed out. A message may only use letters and spaces, so "Hi!" fails because of the "!". The prime must also be bigger than 27, so every letter's number fits under it, and the secret numbers must be between 1 and 57 when the prime is 59.

A ProblemParseException (HTTP 400) disables Run. The backend's reason for (59,2,13,23,"Hi!") is that '!' cannot be encrypted; for (23,5,4,10,"HI"), that a message needs p > 27; for (59,2,0,23,"HI"), that a must satisfy 1 ≤ a ≤ p − 2.

6

Eve's shortcut: baby steps and giant steps

Attack 2: baby-step giant-step (DH Baby-Step Giant-Step)

Look at the grid again: Alice's secret is just row × 8 + column. Eve doesn't need to walk through every square to find which row and column 50 sits in. In 1971 Daniel Shanks found a shortcut, now called baby-step giant-step:

  1. Baby steps: Eve works out the first row only, 8 squares: 1, 2, 4, 8, 16, 32, 5, 10.
  2. Giant steps: she starts from Alice's 50 and moves up one row at a time.
    • One row down = 8 more twos = multiply by 20 (8 twos make 256, which leaves 20).
    • So one row up = undo that = multiply by 3, because 20 × 3 = 60, which leaves 1.
    So each giant step is "multiply by 3 and keep the remainder".
  3. As soon as a giant step lands on a number from her first row, she knows the column, and the number of jumps is the row.

Shanks (1971). Let m = ⌈√(p − 1)⌉ = 8 and write a = i·m + j with 0 ≤ i, j < m. Store the baby steps gj for j < m in a hash table, then compute the giant steps γi = A · (g−m)i for i = 0, 1, ... until γi = gj; then a = i·m + j. Here g−8 mod 59 = 3.

Cost: about 2√p multiplications and √p stored values instead of p, a square-root speed-up that is still exponential in the bit length. Pollard's rho matches the time with constant memory; Pohlig-Hellman reduces the problem to the largest prime factor of p − 1 (here 59 = 2 · 29 + 1 is a safe prime, so that factor is 29). For generic algorithms, which use only the group operation, about √q operations are necessary in a group of prime order q (Shoup, 1997), which is why elliptic-curve groups, where nothing better than generic attacks is known, need only about 256-bit keys.

    For Alice's 50 that is 8 baby steps and 2 giant steps, 10 steps instead of 14. That doesn't sound like much, but as the prime gets bigger, the shortcut's number of steps grows much more slowly: for a prime of about a million, Redux's brute force needs 777,778 tries on the bigger exercise in section 9, and the shortcut needs 1,779.

    Redux's table after baby-step giant-step finds a = 13: giant step 1 matched baby step 5
    The same search in Redux: giant step 1 matched baby step 5, so Alice's secret is 1 × 8 + 5 = 13.Step 1 of the DH Baby-Step Giant-Step run: i = 1, j = 5, m = 8.
    7

    How big does the prime have to be?

    Group size and the cost of discrete logs

    59 has 2 digits, so Eve finds Alice's secret in a moment. Real primes have hundreds of digits. With the slow method, each extra digit makes the list 10 times longer. For a 40-digit prime, the slow method needs a number of tries with about 40 digits; the shortcut needs a number of steps with about 20 digits. That is a huge saving, but still hopeless for big primes. Slide to see what that means for a computer doing a billion steps every second.

    Rough operation counts against the size of p in bits, constants ignored: brute force ~2b; baby-step giant-step and Pollard's rho ~2b/2; the number field sieve for discrete logs, the best known classical method for prime fields, ~exp(1.923 (ln p)1/3 (ln ln p)2/3), the same shape as for factoring; Shor's algorithm ~b3 quantum gates. The vertical axis is logarithmic: each gridline is 1020 times the one below.

    Slow method: tries (about)
    At a billion tries a second
    Shortcut: steps (about)
    At a billion steps a second

    Names like 512-bit and 2048-bit count binary digits, the 0s and 1s computers write numbers with: 512 binary digits is about 155 ordinary digits, and 2048 is about 617. In 2015, researchers showed that some websites still accepted 512-bit primes, which could be broken with smarter methods than the ones on this page. Today 2048-bit primes are common, and many systems use a related kind of mixing built on "elliptic curves" instead.

    The 795-bit marker is the prime-field discrete log record set in 2019 with the number field sieve (Boudot et al., alongside the RSA-240 factorization), which showed a discrete log costs only somewhat more than factoring a number of the same size. 2048-bit groups are a common choice today (for example the RFC 7919 groups for TLS). Logjam (2015) showed that 512-bit "export" groups could be broken in practice after a one-time precomputation. Shor's curve assumes a large, error-corrected quantum computer, which does not exist yet.

    8

    Why quantum computers matter here

    Shor's algorithm for discrete logarithms

    A quantum computer works by the rules of very tiny particles. For most jobs it isn't faster than a normal computer, but for a few special puzzles it is enormously faster. Unmixing Diffie-Hellman's numbers is one of them.

    In 1994 Peter Shor found the method, now called Shor's algorithm (an algorithm is a step-by-step method). A big enough quantum computer running it could find Alice's secret from the numbers Eve sees, even for the sizes used today. Today's quantum computers are much too small and make too many errors to break real Diffie-Hellman, but people are already switching to new kinds of locks that quantum computers can't pick easily. The elliptic-curve versions used widely today fall to Shor's algorithm too.

    Shor's algorithm (1994) solves discrete logarithms in time polynomial in log p. It evaluates f(x, y) = gx Ay mod p = gx + a y on a superposition of (x, y) and applies the quantum Fourier transform to both inputs; a measurement gives (u, v) with v ≡ a·u (mod r), where r is the order of g, so a = v · u−1 mod r whenever u is invertible mod r. The same algorithm breaks elliptic-curve Diffie-Hellman, and resource estimates (Roetteler, Naehrig, Svore and Lauter, 2017) find that elliptic-curve keys need fewer qubits to break than RSA moduli of comparable classical strength. Exercise 5 in section 9 does the classical post-processing for one measurement.

    Quantum computer guides are in progress. They will cover Shor's and Grover's algorithms step by step.

    9

    Things to try in Redux

    Exercises

    Instances are written (prime, starting number, Alice's secret, Bob's secret, "message"). Copy an instance, press Edit on the Diffie-Hellman page, paste it, then Run solve. Redux allows about 10 runs a minute; if it says "Too many runs in a row", wait a few seconds.

    Send your own name

    (59,2,13,23,"YOUR NAME")

    Swap in your name (letters and spaces only). Watch the last row (m, the message) fill in one letter at a time.

    New secret numbers

    (59,2,7,30,"HI")

    Alice picks 7 and Bob picks 30. What do they send each other, and what is their shared secret? Check with the mixing panel in section 2 first.

    Answer

    Alice sends 10 and Bob sends 57. The shared secret is 49, and HI is sent as 38, 28. Eve finds Alice's 7 after 8 tries.

    Only what Eve sees

    (23,5,4,10)

    With four numbers, the instance is Eve's view: the prime 23, the starting number 5, and the two mixes 4 and 10. What is Alice's secret, and the shared secret?

    Answer

    Alice's secret is 4 (found on try 5: 5 × 5 × 5 × 5 = 625, which is 27 × 23 with 4 left over). The shared secret is 10 × 10 × 10 × 10 = 10,000, which leaves 18.

    Catch a wrong answer

    After running the starting instance (59,2,13,23,"Hello World"), open Result and type (12,"HELLO WORLD") in the certificate box, then press Check.

    What happens

    "Not a valid certificate." The message is right, but 12 twos give 25, not 50, so 12 isn't Alice's secret.

    A bigger prime

    (1000003,2,777777,123456,"HELLO WORLD")

    Run it with each attack. How many steps does each one report?

    Answer

    Brute force: 777,778 tries. Baby-step giant-step: 1,779 multiplications. Redux picks a row length that, multiplied by itself, just passes the prime, so rows and columns come out about equal: 1,001 × 1,001 is just over a million. Alice's mix sits in row 777, column 0. Both find Alice's secret 777777 and the message HELLO WORLD.

    Break the rules

    (23,5,4,10,"HI")

    Why won't Redux run this one? (With a message in it, the 4 and 10 are Alice's and Bob's secret numbers, not their mixes.)

    Answer

    23 is smaller than 27. The letter numbers go up to 27, and the prime has to be bigger than every number it locks.

    1. A generator that isn't

    (59,4,2,3)

    What do both solvers report, and why?

    Answer

    "No solution: A = 2 is not a power of g = 4 mod p = 59." 4 = 22 has order 29 and generates only the 29 quadratic residues; 2 is a non-residue mod 59 (59 ≡ 3 mod 8), so no a exists.

    2. A composite modulus

    (55,5,2,3,"HI")

    The instance parses. Run both solvers: why do they fail at different points?

    Answer

    Brute force finds a = 2 (52 = 25 = A), then s = 152 mod 55 = 5 has no inverse mod 55. Baby-step giant-step needs g−1 first and stops because gcd(5, 55) = 5. Both report p is not prime: g and s must be units, and ElGamal decryption needs s invertible.

    3. Which attack scales?

    (1000003,2,777777,123456,"HELLO WORLD")

    Predict m, i and j for baby-step giant-step, and both solvers' step counts, then run them.

    Answer

    m = ⌈√1000002⌉ = 1001; 777777 = 777 · 1001 + 0, so i = 777, j = 0, and m + i + 1 = 1779 multiplications. Brute force: 777,778 tries. Both are exponential in the bit length; BSGS halves the exponent.

    4. The inverse of s

    Compute 40−1 mod 59 by the extended Euclidean algorithm, and check it with Fermat's little theorem.

    Answer

    59 = 1·40 + 19, 40 = 2·19 + 2, 19 = 9·2 + 1, so 1 = 19·59 − 28·40 and 40−1 ≡ −28 ≡ 31. Fermat: 4057 mod 59 = 31 as well.

    5. Shor's post-processing

    For g = 2, A = 50, p = 59 (r = 58), one run of Shor's algorithm measures (u, v) = (5, 7). Recover a. Which values of u would force another run?

    Answer

    5−1 mod 58 = 35, so a = 7 · 35 mod 58 = 245 mod 58 = 13. u must be invertible mod 58: even u and u = 29 share a factor with 58 and need another run (or extra work).

    6. Why not just the message?

    Try the certificate "HELLO WORLD" alone, then explain why the verifier insists on the key.

    Answer

    It is rejected as a certificate format error: the format is (a,"TEXT"). Checking a message needs s, and getting s from (p, g, A, B) is CDH; even recognizing s is DDH. The private key is a witness that can be checked with one modular exponentiation.

    10

    Words to know

    Reference card

    Shared secret
    The number Alice and Bob both end up with, without ever sending it: 40.
    Secret number
    The number each person keeps to themselves: Alice's 13, Bob's 23. Also called a private key.
    Mix
    What each person sends: 2 multiplied by itself as many times as their secret number, then the remainder after dividing by the prime. Alice's is 50, Bob's 47.
    Prime
    A whole number above 1 that divides evenly only by 1 and itself: 2, 3, 5, 7, 11, ..., 59, ...
    Remainder
    What is left over after dividing: 8,192 ÷ 59 is 138 with 50 left over.
    Discrete logarithm
    The answer to "how many twos went into this mix?". Finding it is Eve's whole problem.
    Plaintext, ciphertext
    The message before it is locked (HELLO WORLD), and the locked numbers that travel (25, 23, 8, ...).
    Eavesdropper
    Someone who listens in on a conversation without being part of it. Here, Eve.
    Solver
    In Redux, a method for solving the problem. For Diffie-Hellman, each solver is one of Eve's attacks.
    Certificate
    In Redux, a proposed answer that can be checked. For Diffie-Hellman, Alice's secret number and the message.
    Quantum computer
    A computer that uses the rules of tiny particles. It is much faster at a few special puzzles, including this one.
    ProblemDIFFIEHELLMAN, display name Diffie-Hellman (Problems/NPComplete/NPC_DIFFIEHELLMAN/), page /Diffie-Hellman. Declared complexity class NP; problem type AlgebraAndNumberTheory.
    Instance(p,g,A,B) (Eve's view) or (p,g,a,b,"TEXT") (message mode); p ≥ 3, 1 < g < p, 1 ≤ A, B ≤ p − 1 or 1 ≤ a, b ≤ p − 2; text of letters and spaces needs p > 27. Default (59,2,13,23,"Hello World").
    Encryptionc = m · s mod p per symbol, s = Ba = Ab mod p; decryption m = c · s−1 mod p.
    CertificateAlice's private key a with 0 ≤ a ≤ p − 2 and ga mod p = A; in message mode (a,"TEXT") (any case).
    SolversDH Brute Force Discrete Log (default): x = 0, 1, 2, ... until gx = A; O(p). DH Baby-Step Giant-Step: m = ⌈√(p − 1)⌉, a = i·m + j; O(√p) time and memory. Both finish through the same shared-secret and decryption steps.
    VisualizationDiffie-Hellman Attacker Knowledge Table (DynamicTable): a, then s, then m letter by letter; b stays "?".
    VerifierDefault Diffie-Hellman Verifier: ga = A, then re-encrypt the message with s = Ba.
    SourcesDiffie, W., and Hellman, M. E. (1976). New Directions in Cryptography. IEEE Transactions on Information Theory, 22(6), 644–654. ElGamal, T. (1985). A Public Key Cryptosystem and a Signature Scheme Based on Discrete Logarithms. IEEE Transactions on Information Theory, 31(4), 469–472. Shanks, D. (1971). Class number, a theory of factorization, and genera. Proc. Symp. Pure Math., 20, 415–440.