You are on page 1of 2

Primitive roots and Diffie-Hellman key exchange

The Diffie-Hellman key exchange algorithm starts with the selection of a prime
number plus one of its primitive roots (sometimes called "primitive generators"). So,
what's a primitive root?
If the prime number is p, a primitive root (or generator) g is a number, that
when n goes from 1 to p-1,
then gn mod p goes through all the numbers 1...(p-1) in some order.
gn mod p means the remainder when you raise g to n and divide by p.
An example is worth a thousand words. If 5 is the prime number, let's show that 3 is
one of its primitive roots (there can be many), but 4 is not.
3 is a primitive root of 5:
3n

3n mod 5

27

81

We take all the integers starting with 1, right up to one less than 5, in the first column.
Then we raise our candidate root 3 to each number, generating the sequence of powers
of the candidate root in the second column. We divide that result by our prime, 5, and
record the remainder (that's what 3n mod 5 means). If the set of remainders in the third
column reproduces the set of integers in the first (the order need not be identical), then
3 is a primitive root of 5. It looks like 3 is indeed a primitive root of 5. 4 on the other
hand is not, because we won't get the values 1 through 4 when we repeat the above
process.
4 is not a primitive root of 5:
4x

4x mod 5

16

64

256

The set of integers in the third column is not the same as the set of integers in the first
column. So 4 is not a prime root of 5.
To help do problems like this you can download an use an Excel spreadsheet that
codifies the above procedure. I suggest you do 2 or 3 of them by hand as well, to
make sure you get the idea.
The Diffie-Hellman key exchange algorithm is explained on pages 96-97 of the
textbook (Yuan/Strayer). In it, the two parties select and exchange a prime number
and one of its primitive roots. They also each select (but do not exchange) some
random integer. From those ingredients the algorithm lets them independently
calculate the same key value. Study the explanation in the book to understand the
steps of the algorithm.

You might also like