The "as often as you want" principle: If you are doing modular arithmetic to find
an the answer modulo m, you can take the remainder modulo m as often as you want
during the calculations, without changing the answer.
Example 1. To find 1537 x 4248 modulo 10, you could multiply out and take the last
digit, but a better way would be to replace 1537 by 7 and 4248 by 8 to start, find 7 x 8
= 56, and then take 56 mod 10 to get 6 as the answer.
A handy standard notation is to write a b (mod m) if a and b have the same
remainder modulo m. This is read "a is congruent to b modulo m". In this notation the
example just mentioned looks like this: 1537 x 4248 7 x 8 = 56 6 (mod 10).
Example 2. Find 2
8
(mod 11).
One solution. 2
8
= 256; 11 goes into 256 with quotient 23 and remainder 3.
Another solution. Find 2
2
, 2
4
, 2
8
by squaring repeatedly, but take remainders mod 11
each chance you get: 2
2
= 4, 2
4
= 4
2
= 16 5, 2
8
5
2
= 25 3.
Example 3. Find all the powers of 2 up to 2
10
, each modulo 11.
Solution. Keep doubling, taking remainders modulo 11 whenever possible:
2, 4, 8, 16 5, 10, 20 9, 18 7, 14 3, 6, 12 1 (mod 11). So the answer is 2,
4, 8, 5, 10, 9, 7, 3, 6, 1.
Notice that the powers of 2 run through all possible remainders modulo 11, except 0.
We say 2 is a "generator" modulo 11. There is a theorem that if you take
aprime modulus, then there is always some generator, and in fact 2 often works. If 2
doesn't, maybe 3 will.
C. The Diffie-Hellman method
The idea of Diffie and Hellman is that it's easy to compute powers modulo a prime but
hard to reverse the process: If someone asks which power of 2 modulo 11 is 7, you'd
have to experiment a bit to answer, even though 11 is a small prime. If you use a huge
prime istead, then this becomes a very difficult problem even on a computer. Steps:
1. Alice and Bob, using insecure communication, agree on a huge prime p and a
generator g. They don't care if someone listens in.
2. Alice chooses some large random integer xA < p and keeps it secret. Likewise
Bob chooses xB < p and keeps it secret. These are their "private keys".