Diffie-Hellman Worksheet

Step

1
Intro
2
3
4
5

Private!

Only YOU can see this

You pick a secret number (a) less than n.
a =
We will tell everyone a little about your secret number by revealing the remainder of dividing (g to the power of a) by n. First work this out:
A = g^a = mod n

Take the number that your partner announed (B) and raise it to the power of your secret number (a), then take the remainder after dividing by n.
B^a = mod n

Public!

EVERYONE can see this

Working "mod n"

"mod n" means "the remainder after dividing by n". For example:

15 = 2*6 + 3
15 mod 6 = 3

You can use this calculator to work out values mod n:

= mod
^ = mod
(The value of n is set below)

Another example?

The 12 hour clock works "mod 12". 14 hours after 11 o'clock is:

(11 + 14) mod 12 = (2*12 + 1) mod 12 = 1
o'clock.

Publicly you and your partner choose a large prime (n) and a smaller number (g)
n =
g =
Publicly announce your number (A) and your partner will publicly announce (B).
A =
B =

Private!

Normally only YOUR PARTNER can see this column

(We're showing it to you so you can see how it works.)

Your partner picks their secret number (b), but normally you can't see it!
b =
Your partner also works out something to reveal about b.
B = g^b = mod n
You partner takes the number you announced (A) and raises it to the power of their secret number (b), then takes the remainder after dividing by n.
A^b = mod n

You should both have the same secret number! (Find the equations marked with a cross if you don't.)

Why?

A^b = (g^a)^b = g^(ab) = (g^b)^a = B^a.

Since A^b and B^a are equal normally they are also equal mod n

You should both have the same secret number! (Find the equations marked with a cross if you don't.)

Why?

B^a = (g^b)^a = g^(ab) = (g^a)^b= A^b.

Since A^b and B^a are equal normally they are also equal mod n

Anyone listening in can't work out the secret number!