## Outline

In Diffie-Hellman, Bob and Alice agree on G (a generator) and N (a prime number), and then Bob picks a random value of x, and Alice picks a random value of y:

Bob (x) | Alice (y) |

\(b=G^x \mod N\) | \(a=G^y \mod N\) |

Bob sends Alice the value of b | Alice sends Bob the value of a |

\(Key=a^x \mod N\) | \(Key=b^y \mod N\) |

## Example

Letâ€™s select: G =4 N=7

Bob and Alice generate random numbers (x and y):

X = 3 Y = 4

Bob calculates A:

\(A = G^x \mod N = 4^3 \mod 7 = 64 \mod 7 = 1\)

Alice calculates B:

\(B = G^y \mod N = 4^4 \mod 7 = 256 \mod 7 = 4\)

They swap values and they generate the key:

\(Key_{Bob} = B^x \mod N = 4^3 \mod 7 = 256 \mod 7 = 1\)

\(Key_{Alice} = A^y \mod N = 1^4 \mod 7 = 256 \mod 7 = 1\)

This is their shared key: "1"