How two strangers agree on a secret key over a channel everyone can hear: mixing paint, the same idea in modular arithmetic, and why Eve cannot work out the key herself.
Step 1 of 6 · Mixing paint
Step 1 of 6
Mixing paint
In 1976 Whitfield Diffie and Martin Hellman published a way for two people who have never met to agree on a secret key, while everything they say to each other is overheard. Look inside is open at Mixing paint, a picture that explains the idea.
Alice and Bob agree in public on one colour, yellow. Each secretly chooses a colour of their own, and tells it to nobody. Each mixes their secret into the yellow and sends the mixture down the tube. Watch what passes through the tube, and what each side does with what it receives.
Step 2 of 6
From paint to numbers
The paint is only a picture: paint is easy to mix and hard to unmix. In the real exchange, mixing is replaced by a power mod a prime, from the Lesson on clock arithmetic. The public values are the prime and the generator . Alice chooses a secret and sends ; Bob chooses a secret and sends .
Look inside is still on the paint, and the numbers are hidden: you will do the arithmetic yourself.
Step 3 of 6
Alice’s key
Alice has received from Bob. She raises it to the power of her secret, and gets the shared key:
Step 4 of 6
Bob’s key
Bob does the same with what he received: he works out . Alice and Bob each used a different secret, and never saw the other’s.
Step 5 of 6
Eve’s search
Eve saw everything: , , and . To reach the key she needs one of the secrets, that is, to find the exponent with . That is the discrete logarithm problem. Alice and Bob work out a power in a tiny fraction of a second, even with numbers hundreds of digits long. The other way round, no fast method is known: Eve is left with something like trying exponents one after another.
Step 6 of 6
Public and secret
The Diffie–Hellman exchange opened up public-key cryptography: methods in which part of the key is known to everyone and part is kept secret. In RSA, for example, everyone publishes an open padlock anyone can snap shut, and only they hold the key that opens it; it rests on how hard it is to factor a product of two large primes. Every time a browser connects to a secure website, it runs a key exchange of this kind, with numbers hundreds of digits long.
Loading the interactive version…
Loading the interactive version…
Each step sets up the Scene for you, and a control marked “fixed” stays put for that step.
Practice · Choose
Alice and Bob have never met and share no secret at all. They can talk only through the open tube, and Eve copies everything in it. Can they agree on a shared secret colour?
Practice · Choose
Alice and Bob have never met and share no secret at all. They can talk only through the open tube, and Eve copies everything in it. Can they agree on a shared secret colour?
Practice · Calculate
Now in numbers. The public values: and . Alice’s secret is . What does she send, ?
Practice · Calculate
Now in numbers. The public values: and . Alice’s secret is . What does she send, ?
Practice · Calculate
Bob’s secret is , and he sent . Alice combines it with her own secret, . What is her shared key, ?
Practice · Calculate
Bob’s secret is , and he sent . Alice combines it with her own secret, . What is her shared key, ?
Practice · Predict, then look
Bob got from Alice, and combines it with his own secret: he works out . What will he get? Choose, and then Look inside moves to The maths.
Practice · Predict, then look
Bob got from Alice, and combines it with his own secret: he works out . What will he get? Choose, and then Look inside moves to The maths.
Practice · Reach the target
Now you are Eve. You saw Bob send , and you know and . Find his secret: change Bob’s secret until comes out as , then press Check.
Practice · Reach the target
Now you are Eve. You saw Bob send , and you know and . Find his secret: change Bob’s secret until comes out as , then press Check.
Practice · Choose
Eve has copied , , and . What else does she need to work out the shared key ?
Practice · Choose
Eve has copied , , and . What else does she need to work out the shared key ?
Lesson complete. Every practice question here is done.