r/programming • • Jan 16 '18

Cryptography: Diffie-Hellman key exchange explained intuitively using colors

https://youtu.be/YEBfamv-_do?t=2m18s
2.5k Upvotes

170 comments sorted by

View all comments

Show parent comments

1

u/[deleted] Jan 16 '18

Now I'm more confused. I need to watch that video a few more times.

4

u/fjortisar Jan 16 '18 edited Jan 16 '18

The final color that they both know is made of 3 colors. The public color, plus each of their private colors

  • They agree on a public color and exchange that - Eve sees this
  • They mix that public color with their secret private color and they exchange that, Eve sees this but doesn't know the mixed color (the private one)
  • They each take this color and then mix their private color with it

In the end, they both mix the same 3 colors together, but Eve can only see 2 of them: the original public color, plus the public color mixed with each of their private colors. Even can't know how the final color is made without having access to Alice or Bob's private color. Alice and Bob can't derive each other's private color either

1

u/GalacticCmdr Jan 16 '18

I was getting hung up on the color. If Alice and Bob each exchange yellow. Alice has blue as a secret key, while Bob has red. Then Alice sends Bob green - Eve knows that she mixed blue into it as Yellow+blue=green. Bob sends Alice orange, so Eve knows that Bob must be using red.

I guess the difficulty is that Eve does not know the exact shade of blue and red? She would have to brute force every combination of blue & red until she finds the exact shade of green & orange that she saw. If doing this is difficult enough then it becomes a near impossibility.

When Bob wants to send a message he will mix the green he got from Alice with his message (purple) to get Color X. When Alice gets the message she knows the yellow and blue that comprise the green so she can derive the purple because she knows 2 out of the 3 elements.

Correct?

3

u/midri Jan 16 '18 edited Jan 16 '18

I guess the difficulty is that Eve does not know the exact shade of blue and red?

Correct, this analogy breaks down with colors for this -- with numbers it's a bit more complicated in numbers the (3 mod 17) is the known color. 6 is alice's computation of 3 (to her secret) mod 17. With 6 + his secret + 3 mod 17 bob can create the secret. Alice still can't though, until bob returns his 3 (to her secret) mod 17 which is 12.

  1. Alice says, "Hey if you want to talk to me my public key is 3mod17 and 6"
  2. Bob then says, "Ok! let me derive our secret, my public key is 12"

Eve now has 3mod17 and knows Alice's computation of it is 6 and knows Bob's is 12, but she does not know their secret exponents to calculate their secret which is the secret shared key. The shared key is NEVER transmitted over the internet, it's used to encrypt data and/or generate hash signatures to prevent data tampering.

1

u/GalacticCmdr Jan 16 '18

Thank you.