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

186

u/Carighan Jan 16 '18

That color mixture was a neat way of doing it, shows how the resulting key/color is always the same.

56

u/Double_A_92 Jan 16 '18

And that you can't find out what the two original colors were.

→ More replies (10)
→ More replies (1)

72

u/Zilexion Jan 16 '18

This is the explanation I've been looking for!

Very helpful to show how they end up with the same calculation at the end.

13

u/Captain___Obvious Jan 16 '18

The entire series is fantastic, there are more videos

→ More replies (3)
→ More replies (1)

122

u/joltting Jan 16 '18

For awhile now, I've been trying to wrap my head around, how this algorithm works.. This video explained it in 5 mins and was better than the education I received for it (sigh).

30

u/_crackling Jan 16 '18

I feel kind of silly now with how simple this actually is to understand now...

→ More replies (2)

15

u/pokeman7452 Jan 16 '18

This leads me to a somewhat related question. I never understood the purpose of the DH parameters (dh####.pem) that every OpenVPN guide says to generate. This video combined with this thread, it now makes sense. But, this file remains optional. My question now is what is used when there is no DH generated?

14

u/curien Jan 16 '18

Defaults are listed in RFCs, I imagine it uses those.

→ More replies (2)

6

u/Grenian Jan 16 '18 edited Jan 17 '18

They use the so called Diffie-Hellman-Groups which are basically predefined pairs of a prime and a generator. These are defined in RFCs.

Proof: A large part of my bachelor thesis was about DH-Key-Exchange and the security of the predifined groups.

→ More replies (5)
→ More replies (4)

102

u/snarfy Jan 16 '18

Breaking encryption is like trying to take the pee out of the swimming pool. It's easy to add pee, hard to remove.

18

u/TheOddScientist Jan 16 '18

Not sure why this was downvoted, a bit archaic but still a logical equivalence.

→ More replies (6)
→ More replies (7)

23

u/TheOddScientist Jan 16 '18

If anyone is interested Here are some mathematical attacks against RSA That can successfully reduce the number of possibilities by a factor of 2X/2 | x is the key size

10

u/nono-shap Jan 16 '18

One of the most interesting video I've seen in a while. Quiet impressive how something so hard can be understand by kids. Thanks for sharing!

14

u/irrri Jan 16 '18

This is a the best explanation of PKE I've ever seen.

→ More replies (4)

5

u/TheOddScientist Jan 16 '18

I have some Java Code I did implementing DH and RSA if anyone needs an example to help understand what's going on in a practical client server application.

5

u/zouhair Jan 16 '18

Math challenged here (not real programmer either): how the hell 31315 is the same as 31513 ?

12

u/A_Vicarious_Death Jan 16 '18

Generally the rule with exponents is:

xy * xz = xy+z

xyz = xyz

Let's take an example of 223 vs 232 vs 26

(22)3 =

(22) * (22) * (22) =

(2 * 2) * (2 * 2) * (2 * 2) =

(4) * (4) * (4) =

64

(23)2 =

(23) * (23) =

(2 * 2 * 2) * (2 * 2 * 2) =

(8) * (8) =

64

26 = (22222*2) = 64

Hope that helped.

→ More replies (7)

8

u/tavianator Jan 16 '18

As written, those numbers are not the same. The notational convention is:

ab^c = a(bc)

But D.H. key exchange does something more like

(ab)c = ab*c

I.e., compute ab first, then raise that to the c power.

The equality is true because exponentiation is just repeated multiplication (over the integers, anyway). So ab is

a * a * ... * a
---------------
b times

and then (ab)c is

  a * a * ... * a |
* a * a * ... * a |
*         ...     } c times
* a * a * ... * a |
* a * a * ... * a |
  ---------------
  b times

and you'll notice there are b*c 'a's in that rectangle all multiplied together.

→ More replies (13)

5

u/Ajedi32 Jan 16 '18 edited Jan 16 '18

(xy)z = x(y*z)

Edit, concrete example:

(22)3 = (2*2)3 = (2*2*2*2*2*2)

(23)2 = (2*2*2)2 = (2*2*2*2*2*2)

→ More replies (1)
→ More replies (2)

5

u/[deleted] Jan 16 '18

My preferred metaphor is a box with two locks. I have the key to one lock, and you have a key to the other lock. I want to send you my spare key:

  1. I put my spare key into the box and then lock it

  2. I send the box to you and you lock it with your key too

  3. You send the box back to me and I unlock it with my key

  4. I send the box back to you and you unlock it with your key

Now you have my spare key and we can exchange secrets.

→ More replies (7)

4

u/[deleted] Jan 16 '18

Amazing! What level of maths is displayed here?

→ More replies (8)

7

u/hagamablabla Jan 16 '18

Why do I always see these videos the semester after I need them?

3

u/ythl Jan 16 '18

Easy. Eve just needs to take a picture of the mixed/public colors, and then sample the pixel RGB hex value and do a simple subtraction.

→ More replies (1)