Mixing a secret in plain sight

Diffie-Hellman lets two people who have never met agree on a secret while someone listens to every word. Start with paint, then follow the same idea into the math your browser uses on every HTTPS connection.

Public
Alice's secret
Bob's secret
Shared secret

Paint studio

Alice and Bob want the same secret paint. Everything they send crosses a public channel, and Eve copies all of it. Mixing paint is easy; un-mixing it is not.

  1. 1Agree on a public paint
  2. 2Pick secret paints
  3. 3Mix and send
  4. 4Add your own secret

Alice

Alice's secret paint

Unlocks at step 2

Alice's mix to send

Unlocks at step 3

Alice's final pot

Bob's mix + Alice's secret

Unlocks at step 4

Public channel Eve is copying everything

Public paint (everyone knows it)

In transit

Alice's mix, on its way to Bob
Bob's mix, on its way to Alice

Unlocks at step 3

Eve's notebook

    Bob

    Bob's secret paint

    Unlocks at step 2

    Bob's mix to send

    Unlocks at step 3

    Bob's final pot

    Alice's mix + Bob's secret

    Unlocks at step 4

    Where the paint analogy breaks

    Paint is a great picture of the idea, but it isn't a perfect model. A chemist with a spectrometer could probably work out which pigments went into a mix, so "un-mixing" is hard rather than impossible. Real Diffie-Hellman replaces paint with modular exponentiation, where reversing the step (the discrete logarithm problem) has no known fast method for well-chosen numbers on classical computers.

    Paint also hides how much secret is in play. There are only a few thousand paint colors anyone could tell apart, while a 2048-bit Diffie-Hellman secret has a number of possibilities with more than 600 digits. The Play as Eve and Brute-force race tabs make that difference concrete.