Docsity

Number Theory II: Modular Arithmetic, Cryptography, and Randomness, Lecture notes of Number Theory

Toggle sidebar
bg1
last edited April 30, 2016
6 Number Theory II: Modular Arithmetic,
Cryptography, and Randomness
For hundreds of years, number theory was among the least practical of math-
ematical disciplines. In contrast to subjects such as arithmetic and geometry,
which proved useful in everyday problems in commerce and architecture, as-
tronomy, mechanics, and countless other areas, number theory studies very ab-
stract ideas called numbers, and applications of the subject are not immediate.
Over the course of the second half of the twentieth century, however, number
theory became increasingly more applicable, and today make possible a wide
range of technologies. In this section we will consider modular arithmetic
and applications to cryptography and to generating “random numbers”by
deterministic computers.
6.1 Introduction to Cryptography
Since ancient times, people desiring to transmit messages privately have devised
methods of encoding messages, so that no p erson but the intended recipient
could read the message. The ability to successfully encode and decode messages
has played a central role in the development of financial markets and in history-
altering military turnarounds. We use cryptography to refer to the study of
how information can be made secretive enough so that bad people can’t read
it, yet still accessible enough so that good guys can. Cryptography is a very
exciting and developing area of contemporary mathematics, with connections
to number theory and computational complexity.
Let us consider a person Alice who would like to send a secret message to
another person Bob. Perhaps Alice and Bob are childhood friends and are plan-
ning a surprise birthday party for a mutual friend. Or perhaps Alice and Bob
have never met, but Alice would would like to send Bob her credit card informa-
tion so she can pay for something Bob is selling. In both cases, Alice and Bob
would like to guarantee several things: (a) Alice would like to ascertain that
Bob has received her message; (b) both Alice and Bob would like to know that
no one else has seen the secret message; (c) Bob would like to ascertain that
the message he believes to have come from Alice has indeed come from Alice.
It is not immediately clear how we can guarantee each of these except in the
case where Alice and Bob actually meet up and Alice whispers the message into
Bob’s ear. What should they do, however, if they are far apart? If they send a
message through the postal service, there is a small chance that (notwithstand-
ing the serious federal crime involved in opening someone else’s mail) that an
eavesdropper might intercept the message before it reaches Bob. Even if they
use the telephone, or an email, or a text, there is a chance that the intended
message and information will make its way to the wrong hands. These kinds
of questions motivate the need to develop methods of encoding and decoding
information so that messages can be communicated securely.
70
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a

Partial preview of the text

Download Number Theory II: Modular Arithmetic, Cryptography, and Randomness and more Lecture notes Number Theory in PDF only on Docsity!

6 Number Theory II: Modular Arithmetic,

Cryptography, and Randomness

For hundreds of years, number theory was among the least practical of math- ematical disciplines. In contrast to subjects such as arithmetic and geometry, which proved useful in everyday problems in commerce and architecture, as- tronomy, mechanics, and countless other areas, number theory studies very ab- stract ideas called numbers, and applications of the subject are not immediate. Over the course of the second half of the twentieth century, however, number theory became increasingly more applicable, and today make possible a wide range of technologies. In this section we will consider modular arithmetic and applications to cryptography and to generating “random numbers” by deterministic computers.

6.1 Introduction to Cryptography

Since ancient times, people desiring to transmit messages privately have devised methods of encoding messages, so that no person but the intended recipient could read the message. The ability to successfully encode and decode messages has played a central role in the development of financial markets and in history- altering military turnarounds. We use cryptography to refer to the study of how information can be made secretive enough so that bad people can’t read it, yet still accessible enough so that good guys can. Cryptography is a very exciting and developing area of contemporary mathematics, with connections to number theory and computational complexity. Let us consider a person Alice who would like to send a secret message to another person Bob. Perhaps Alice and Bob are childhood friends and are plan- ning a surprise birthday party for a mutual friend. Or perhaps Alice and Bob have never met, but Alice would would like to send Bob her credit card informa- tion so she can pay for something Bob is selling. In both cases, Alice and Bob would like to guarantee several things: (a) Alice would like to ascertain that Bob has received her message; (b) both Alice and Bob would like to know that no one else has seen the secret message; (c) Bob would like to ascertain that the message he believes to have come from Alice has indeed come from Alice. It is not immediately clear how we can guarantee each of these except in the case where Alice and Bob actually meet up and Alice whispers the message into Bob’s ear. What should they do, however, if they are far apart? If they send a message through the postal service, there is a small chance that (notwithstand- ing the serious federal crime involved in opening someone else’s mail) that an eavesdropper might intercept the message before it reaches Bob. Even if they use the telephone, or an email, or a text, there is a chance that the intended message and information will make its way to the wrong hands. These kinds of questions motivate the need to develop methods of encoding and decoding information so that messages can be communicated securely.

We briefly note several methods used to solve some of the above problems. Bob can send back a note saying “I received your message”, though the same security concerns relevant to the initial message will be relevant here as well. Signing one’s signature to a piece of a paper is a relatively simple way in which Alice can convince that the message indeed came from her. This is partly because while reading and identifying a signature is relatively easy, actually creating it is complicated, for all except the person signing it (though of course signatures can be forged). In this section, we will focus mostly on the problem (b), that is, how can we ensure that no eavesdropper can read the message intended solely for Bob. Simple ways of encoding messages were known since antiquity. Sometimes letters were switched for other letters, or for numbers, and so an eavesdropper quickly looking at an encoded message would only see gibberish. However, this approach has many limitation. For starters, how would Alice communicate to Bob the scheme which she used to encode the message and which he, conse- quently, will need to decode it? If he can determine this by himself, perhaps through some guesswork, then what would stop someone else from doing the same? Many somewhat sophisticated methods have been developed over the centuries for encoding and decoding secret messages, though in this section we will focus on one that is built on what is called modular arithmetic, a system of arithmetic that in some sense only has a finite number of numbers.

The central definition in studying modular arithmetic systems establishes a relationship between pairs of numbers with respect to a special number m called the modulus:

Definition 25. Two integers a and b are congruent modulo m if they di↵er by an integer multiple of m, i.e., b a = km for some k 2 Z. This equivalence is written a ⌘ b (mod m).

Although this definition looks somewhat technical, the idea is very simple. For some fixed integer m, two numbers are roughly the same if they di↵er by multiples of m. In a sense, this definition generalizes previous discussions of odd and even numbers. In previous sections, we proved theorems such as the square of an even number is even and the square of odd number is odd. As far as even and odds numbers go, and as far as these theorems are concerned, there is no di↵erence between 17 and 2073, as both are odd and behave the same under squaring. In a similar manner, in modular arithmetic, there is no di↵erence between a pair of numbers that di↵er by the modulus m, which could be 2 or could be 15,485,863. In arithmetic mod 7, for example, there is no di↵erence between 1, 8, and 15, as they all di↵er from one another by multiples of 7. Likewise, 22, 701 and -6 also di↵er from all of these numbers by multiples of 7, and are hence congruent.

Example 1. Every number is congruent to itself for any modulus; that is, a ⌘ a (mod m) for any a, m 2 Z. The reason for this is that a a = 0, which is a multiple of m, since 0 = 0 ⇥ m for any m. It might seem a bit silly, but is a consequence of the way in which we defined congruence.

Example 2. Every number is congruent to any other number mod 1; that is, a ⌘ b (mod 1) for any a, b 2 Z. The reason for this is that b a, is a multiple of 1 for any a and b. Again, this might seem a bit silly, but is a consequence of the way in which we defined congruence.

Example 3. Any even numbers are congruent to one another mod 2; likewise, any odd numbers are congruent to one another mod 2. For example, we have 12 ⌘ 3132 (mod 2) and 7 ⌘ 19 (mod 3). This is because any pair of even numbers di↵er from one another by a multiple of 2. Likewise, any pair of odd numbers di↵er from one another by a multiple of 2.

Example 4. The numbers 31 and 46 are congruent mod 3 because they di↵er by a multiple of 3. We can write this as 31 ⌘ 46 (mod 3). Since the di↵erence between 31 and 46 is 15, then these numbers also di↵er by a multiple of 5; i.e., 31 ⌘ 46 (mod 5).

Example 5. By the definition of congruence, every pair of integers a and b are congruent mod 1, since any pair of integers di↵er by a multiple of 1. In symbols, for all integers a and b, we have a ⌘ b (mod 1).

Example 6. In general it is not true that a ⌘ a (mod m), unless m = 2 or else a is a multiple of 2. For example, it is not true that 7 ⌘ 7 (mod 3), since the di↵erence between 7 and -7 is 14, which is not a multiple of 3.

Rules of Modular Arithmetic

After considering the basic definition of modular arithmetic, we next consider some of its basic properties. It turns out that modular arithmetic follows many of the same rules of classical arithmetic, thus making it very easy to work with. In order to highlight what is going on, we try to compare and contrast modular arithmetic to classical arithmetic. Suppose we have two numbers a and b:

a = 5 b = 8.

We all know that in classical arithmetic we can combine these equations to obtain:

a + b = 5 + 8 = 13.

More generally, if we have

a = c b = d,

then we can combine them in many di↵erent ways, to obtain:

a + b = c + d, a b = c d, a ⇥ b = c ⇥ d.

Pause to think about this statement, and make sure it aligns with what you know. Of course these are only several ways of combining these equations, and every reader can think of several others. All of the above are “rules” of classical arithmetic. What we would like to do now is consider whether similar rules apply to modular arithmetic as well. Suppose we have the following two congruence relations:

a ⌘ b (mod m) c ⌘ d (mod m).

Are we able to combine these to obtain

a + b ⌘ c + d (mod m), a b ⌘ c d (mod m), a ⇥ b ⌘ c ⇥ d (mod m)?

That is, do the rules that govern how we can combine equations in classical arithmetic also govern the ways in which we combine statements in modular arithmetic? In what follows we prove that indeed many of the rules do carry over – the rules of modular arithmetic will be familiar to us.

Multiplication

After understanding how addition and subtraction work in modular arithmetic, we turn our attention to understanding multiplication. In classical arithmetic, if a = 2 and b = 5, then of course a ⇥ b = 2 ⇥ 5 = 10. Does a similar relationship also hold in modular arithmetic? In particular, if we know that a ⌘ 2 (mod m) and b ⌘ 5 (mod m), do we know that a ⇥ b ⌘ 2 ⇥ 5 (mod m)? The following theorem answers this question armatively.

Theorem 16.

If a ⌘ b (mod m) and c ⌘ d (mod m), then a ⇥ c ⌘ b ⇥ d (mod m).

Proof. By the definition of congruence we know that a and b di↵er by a multiple of m, as do c and d:

b a = jm d c = km

for some j, k 2 Z. Note that we use distinct multiples j and k for the two equations, since a and b might di↵er by one multiple of m, and c and d might di↵er by another multiple of m. To prove the desired result, we rearrange the equations:

b = jm + a d = km + c

We multiply both sides by each other to obtain

bd = (jm + a)(km + c) = jkm^2 + jmc + kma + ac = (jkm + jc + ka)m + ac.

We then subtract ac from both sides to obtain

bd ac = (jkm + jc + ka)m.

Since (jkm + jc + ka)m is an integer multiple of m, then ac and bd di↵er by an integer multiple of m, and so by definition are congruent mod m.

Example 1. If we know that a ⌘ 3 (mod 7) and we know that b ⌘ 4 (mod 7), then we can determine that ab ⌘ 12 ⌘ 5 (mod 7). This is true whether a is 10, 703, or 7,000,003 and whether b is 7004 or 10000. In any of these cases, the product ab will be congruent to 5 modulo 7.

Example 2. How can we simplify 20 ⇥ 21 in arithmetic modulo 19? We first note that 20 ⌘ 1 (mod 19) and also that 21 ⌘ 2 (mod 19). Theorem 16 tells us that we can combine these equations to obtain 20 ⇥ 21 ⌘ 1 ⇥ 2 ⌘ 2 (mod 19).

Example 3. Can we simplify 17 753 in arithmetic modulo 9? We first note that 17 ⌘ 1 (mod 9), because 17 and -1 di↵er by a multiple of 9. Theorem 16 allows us to then combine this congruence relation as many times as we would like. In particular, by combining 753 copies, we obtain 17^753 ⌘ (1) 753 (mod 9). Since (1) n^ = 1 for any odd integer n, we have 17^753 ⌘ 1 (mod 9). Finally, if we would like to have a simple, positive answer, then we can add 9 to obtain a final answer of 8.

Theorems 15 and 16 show us that we can treat all numbers that are congruent modulo m as the same, in addition and in multiplication operations. Division is much more complicated, and will not be discussed.

Remainders

We take a moment to draw out a connection to division with remainders, an idea we considered briefly in Section 4.1. In particular, back in elementary school we learned about a way of dividing integers by other integers that entirely avoids decimals and fractions. In particular, suppose we divide 7 by 4. In third, fourth, or fifth grade, we learned that we can write this as 1, remainder 3. That is, 4 can 1 time “into” 7, leaving over 3. As we got older, we learned that we could also write the answer as 1.75 or 1^3 ⁄ 4 , but we still occasionally deal with situations in which discussing fractions would be silly. If we have 52 playing cards and 5 players, a dealer could give each player 10 cards and then be left with 2 cards. It makes little sense to say that the dealer should give each player 10.2, or 10 and a fifth, cards. What is the connection of modular arithmetic to division with remainders? Suppose that we divide some integer a by another integer m. Notice that the “remainder” is always congruent to a modulo m. For example, suppose we divide 1031 by 19. We obtain 54, remainder 5. This tells us that 5 is congruent to 1031 modulo 19. Likewise, since the remainder of 7381/57 is 28, we know that 28 ⌘ 7381 (mod 57). Why is the remainder after division always congruent to the number we are dividing? One way to think about this is by considering how we can find a remainder without actually doing any division. Suppose we want to know the remainder of 11 after dividing by 3. We can subtract 3 over and over until we obtain a number that is smaller than 3: 11, 8, 5, and eventually 2. Each time we subtract 3, we are realizing that 3 can “go into” 11 one more time; whatever is left at the end is the remainder. At the same time, we got from the original number to the remainder by jumps of 3, so of course the di↵erence between 11 and 2 is divisible by 3, making 11 and 2 congruent. The same idea works for dividing any number a with any other number m.

easy to see that if n is odd then (1) n^ = 1, and if n is even then (1) n^ = 1. Since 489391312 is even, 18^489391312 ⌘ 1 (mod 19).

Dividing by 9

We can use the rules of modular addition and multiplication to prove a theorem you may have once seen. Suppose we have a number, for example 2,383,623, and want to know whether it is divisible by 9. Is there an easy way to figure this out without doing “long division”? You may have learned the following trick: add up the digits of the number (e..g., 2 + 3 + 8 + 3 + 6 + 2 + 3 = 27). If this sum is divisible by 9, then so is the original number; if the sum is not divisible by 9, then neither is the original number. Is this just a miraculous trick, or is it something that we can prove should work? The rules of modular addition and multiplication (Theorems 15 and 16 above) can help us prove this beautiful result. Let’s begin by proving a sim- pler result about the remainders we get when we divide powers of 10 by 9. In particular, the remainder is always 1.

Lemma 17. For any natural number n, we have 10 n^ ⌘ 1 (mod 9).

Proof. Recall that if we have two congruences: a ⌘ b and c ⌘ d (mod m), then we can combine them to form a new congruence relation: ac ⌘ bd (mod m). Since 10 ⌘ 1 (mod 9), then we can combine the equation with itself to obtain 100 = 10 ⇥ 10 ⌘ 1 ⇥ 1 ⌘ 1 (mod 9). We can indeed combine this equation with itself as many times as we want (e.g., n times), and therefore have 10n^ ⌘ 1 n^ ⌘ 1 (mod 9) for any natural number n.

Next, let’s consider what happens when we divide numbers such as 300, 5000, and 2,000,000 by 9. What are the remainders? Theorem 16 can help us see that the remainders are 3, 5, and 2 in these examples. To see why this is so, notice that each of these numbers can be written as the product of an integer and a power of 10: 300 = 3 · 102 , 5000 = 5 · 10 3 , and 2,000,000= 2 · 10 6. This leads us to the following theorem.

Lemma 18. For any natural numbers c and n, we have c · 10 n^ ⌘ c (mod 9).

Proof. Recall that if we have two congruences: a ⌘ b and c ⌘ d (mod m), then we can combine them to form a new congruence relation: ac ⌘ bd (mod m). Since c ⌘ c and 10 n^ ⌘ 1 (mod 9) for any n, then we can combine the equations to obtain c · 10 n^ ⌘ c · 1 ⌘ c (mod 9).

This now leads us to our central theorem:

Theorem 19. A number is divisible by 9 if and only if the sum of its digits (written in base 10) is divisible by 9.

Proof. In base 10, every number can be written as a sum of ones, tens, hundreds, thousands, and so forth. For example, 5776 = 5000+700+70+6. More generally, we can write this as n = c 0 + c 1 10 1 + c 2 10 2 + c 3 10 3 +.. ., where the c (^) i variables

are the numbers of ones, tens, hundreds, thousands, and so forth. According to Lemma 18, for each of the c (^) i we have c (^) i · 10 n^ ⌘ c (^) i (mod 9). Using Theorem 15, we can combine the congruence relations

c 0 ⌘ c 0 (mod 9), c 1 ⌘ c 1 101 (mod 9), c 2 ⌘ c 2 102 (mod 9), c 3 ⌘ c 2 103 (mod 9),

... c (^) n ⌘ c 2 10 n^ (mod 9),

to give us

c 0 + c 1 101 + c 2 10 2 +... c (^) n 10 n^ ⌘ c 0 + c 1 + c 2 +... c (^) n (mod 9) (69)

In other words, a number n is congruent to the sum of its digits in mod 9. If a number is divisible by 9, i.e., n ⌘ 0 (mod 9), then so is the sum of its digits.

Theorem.

If a ⌘ b (mod m) and c ⌘ d (mod m), then a ⇥ c ⌘ b ⇥ d (mod m).

In our particular case, we know that

10 1 ⌘ 1 (mod 3), and 10 1 ⌘ 1 (mod 3).

Of course these are the same equation, but writing them out in this way allows us to think of them in terms of the previous theorem. More specifically, this theorem allows us to multiply both sides of the equation together, to get:

10 1 ⇥ 10 1 ⌘ 1 ⇥ 1 (mod 3), 10 2 ⌘ 1 (mod 3).

We can then use the same technique, through induction, to show that all integer powers of 10 are congruent to 1 mod 3, since we can continue multiplying our resulting equation by the initial equation 10^1 ⌘ 1 (mod 3). In other words, all positive integer powers of 10, when divided by 3, give us a remainder of 1! We have chosen a relatively simple case to highlight the usefulness of The- orem 2 for simplifying what might otherwise be very complicated calculations. We now consider several more complex examples in which we can determine patterns as we consider a n^ (mod m) as n increases.

Example 1. Consider the very large number 7^1383921 and how we might de- termine its remainder after dividing it by 4. Of course we know that the only possible remainder are 0, 1, 2, and 3, but it is not clear how to determine which of those it is. Simple calculations show the following pattern:

71 ⌘ 3 (mod 4), 72 ⌘ 1 (mod 4), 73 ⌘ 3 (mod 4), 74 ⌘ 1 (mod 4),...

It seems that if n is odd, then 7n^ ⌘ 3 (mod 4), and if n is even, then 7n^ ⌘ 1 (mod 4). We can prove that this pattern will repeat as n increases by noticing that 7 2 ⌘ 1 (mod 4). Combining this with Theorem 16 shows that if 7 n^ ⌘ 3 (mod 4) then 7 n+2^ ⌘ 3 (mod 4), and likewise if 7n^ ⌘ 1 (mod 4) then 7n+2^ ⌘ 1 (mod 4). Therefore, the pattern repeats with a period of 2. Determining the remainder of 7^1383921 when dividing by 4 is then straightforward – since the exponent n = 1383921 is odd, the remainder must be 3.

Example 2. Let us consider the very large number 4 2349321230 and determine its remainder after dividing it by 15. Of course we know that the only possible

solutions are in { 0 , 1 , 2 ,... , 14 }, but that is still a wide range of options, and it is not clear how to determine which of those it is. Simple calculations show the following pattern:

41 ⌘ 4 (mod 15), 42 ⌘ 1 (mod 15), 43 ⌘ 4 (mod 15), 44 ⌘ 1 (mod 15),...

It seems that if the exponent n is odd, then 4n^ ⌘ 4 (mod 15), and if n is even, then 4 n^ ⌘ 1 (mod 15). This pattern too will repeat ad infinitum, because in this case we have 4 2 ⌘ 1 (mod 15), and so increasing the exponent n by 2 will never change the remainder mod 15, and 4n^ ⌘ 4 n+2^ (mod 15) for all exponents n. Determining the remainder of 4 2349321230 when dividing by 15 is then straightforward – since the exponent n = 2349321230 is even, the remainder must be 1.

Example 3. The particular patterns need not have a length of 2, and indeed most of the time they don’t. Here we consider a repeating pattern with a slightly longer period. Let us consider the very large number 7 30001 and determine its remainder after dividing by 18. Simple calculations show the following pattern:

7 1 ⌘ 7 (mod 18), 7 2 ⌘ 13 (mod 18), 7 3 ⌘ 1 (mod 18), 7 4 ⌘ 7 (mod 18), 7 5 ⌘ 13 (mod 18), 7 6 ⌘ 1 (mod 18),...

Here the pattern repeats every 3, because 4 3 ⌘ 1 (mod 18) and so increasing n by 3 will never change the remainder mod 18. Determining the remainder of 7 30001 when dividing by 18 then requires us to look at the exponent n = 30001. Since adding and subtracting multiple of 3 from this number will not change the remainder, we should subtract from it 30000, which of course is a multiple of 3. We can then determine that 7 30001 ⌘ 71 ⌘ 7 (mod 18).

Example 4. Here we consider a repeating pattern with a period of 4. Let us consider remainders of all numbers 5n^ after dividing them by 13. Simple calculations show the following pattern:

51 ⌘ 5 (mod 13), 52 ⌘ 12 (mod 13), 53 ⌘ 8 (mod 13), 54 ⌘ 1 (mod 13), 55 ⌘ 5 (mod 13), 56 ⌘ 12 (mod 13),...

to repeat again. The longest possible pattern then includes all integers between 1 and m 1, but not 0, as explained. Therefore, if we are dividing powers of a by m, then the maximum length of a repeating pattern of remainders is m 1. To see that this is indeed possible, consider the remainders of 5 1 , 5 2 , 53 ,... when divided by m = 277. We obtain: 5, 25, 125, 71, 78, 113, 11, 55,... ; the pattern will not repeat before we reach 5^277 , which is congruent to 5 and which thus begins the pattern again. Now that we are aware of patterns with very long periods, the approach of finding short patterns will not always help us simplify large exponents. Fermat’s Little Theorem gives us an alternate shortcut for computing modular remainders of large exponents.

Fermat’s Little Theorem

As we have seen, every sequence of powers a 1 , a 2 , a 3 ,... (mod m) will eventually form a repeating pattern, which can be as long as m 1. If the length of such a pattern is m 1, then multiplying any number by a m^1 is equivalent to multiplying it by 1. In the language of modular arithmetic, this can be stated a m^1 ⌘ 1 (mod m). Fermat’s Little Theorem, which we will not prove here, can be thought of as a generalization of this result that does not involve consideration of repeating patterns. More specifically:

Theorem 20 (Fermat’s Little Theorem). If a is an integer and p is a prime number that does not divide a, then a p^1 ⌘ 1 (mod p).

You may have noticed the requirement that p does not divide a. Why is this? To explain this, it pays to consider an example where p does divide a. Consider what happens, for example, if a = 20 and p = 5. Of course p = 5 is a prime number, but it is also clear that a p^1 ⌘ 0 (mod p), since 5 evenly divides 20, and so there is never a remainder after dividing 20, or any power of it, by 5. So Fermat’s Little Theorem can only consider cases where p does not divide a.

Example 1. Example 1. What is the remainder of 50^72 when divided by 73? Since 73 is a prime number, and since 50 is not a multiple of 73, then we have 50 72 ⌘ 1 (mod 73). So the remainder of 50 72 when divided by 73 is 1.

Example 2. What is the remainder of 100^10 when it is divided by 11? Since 11 is a prime number, and since 100 is not a multiple of 11, then we have 100^10 ⌘ 1 (mod 11). So the remainder of 100^10 when divided by 11 is 1. Of course we can combine this congruence relation with itself (using Theorem 16) to obtain 100 20 = 100^10 ⇥ 100 10 ⌘ 1 ⇥ 1 = 1 (mod 11). The same process can be repeated to show that 100 30 , 100 40 , etc, are also congruent to 1 mod 11.

Example 3. What is the remainder of 3 49 when divided by 7? Fermat’s Little Theorem tells us that 3^6 ⌘ 1 mod 7, so we write 3^50 in terms of 3 6. We can write this as 3^49 = 3 · (3^6 ) 8 , which we can then reduce: 3 · (3 6 ) 8 ⌘ 3 · 1 8 ⌘ 3 (mod 7).

Example 4. What is the remainder of 2^432 when divided by 11? Of course 11 is a prime number, but the exponent here is not p 1, so how can we use Fermat’s Little Theorem to help us? We can rewrite 2^432 as 2 430 22 = (2^10 ) 43 2 2. Note that Fermat’s Little Theorem tells us that 2 10 ⌘ 1 mod 10, which means that we can replace 2^10 in this equation with 1. So we have 2 432 = 2^430 22 = (2 10 ) 43 22 ⌘ 143 22 ⌘ 1 · 22 ⌘ 4 (mod 1)1. Hence, the remainder of dividing 2^432 by 11 is 4.

Example 5. What is 29^25 (mod 11)? Fermat’s Little Theorem tells us that 29 10 ⌘ 1 (mod 11), so we want to rewrite 29^25 as 29^10 · 29 10 · 29 5. We then have 29 25 ⌘ 29 10 · 29 10 · 295 ⌘ 1 · 1 · 29 5 ⌘ 295 (mod 11). Since 29 ⌘ 7 (mod 11), we can further simplify this to 7 5 = 7^2 · 72 · 7 ⌘ 49 · 49 · 7 ⌘ 5 · 5 · 7 ⌘ 10 (mod 11).

Example 6. What is 1^10 +2 20 +3 30 +4 40 +5 50 +6 60 (mod 11)? Fermat’s Little Theorem has a 10 ⌘ 1 (mod 11) for each term. Even when we take multiples of the exponent 10, we still have the same result. Therefore, each term contributes 1, and so the answer is the number of terms, 6.

Notice that each problem is di↵erent and requires thinking. Oftentimes, rewriting a large exponent as the product of smaller exponents can enable the use of patterns of Fermat’s Little Theorem to further simplify a problem.

you’ve mixed. These paints are di↵erent, but you can now make them the same quite easily. Each of you adds to the paint in your hands the exact amount of whatever paint you’ve chosen and added to the other paint. The two paints are now identical and only the two of you have that color, since anyone in the middle who has seen the paint in transit has no way of determining what color and what amount each of you have added. This beautiful “thought experiment” shows that it is possible for two people to work together to create information that is known only to them and secret from everyone else, even though they have shared some information publicly. This idea motivates the development of the Die-Hellman key-exchange proto- col that is used regularly by computers when information must be sent securely. Of course computers do not send paints to one another, but through modular arithmetic they are able to achieve a similar result.

Die-Hellman Key Exchange

Alice and Bob would like to communicate securely. The Die-Hellman key exchange protocol allows them to work together to create a password that only the two of them will know, even while some of the information they exchange is completely public. To do this, they use numbers instead of paints. More specifically, they agree (publicly) on a modulus m and an integer g, which is smaller than m and which serves as their “white paint”. Next, each of Alice and Bob chooses another secret number which they will share with nobody; we will use a to refer to Alice’s secret number and b to refer to Bob’s secret number. Alice then calculates g a^ (mod m) and Bob calculates g b^ (mod m). Like with the paints, it is easy to create these numbers but almost impossible to figure out how they were made. That is, if you just know g, m, and g a^ (mod m), there is no known way of eciently determining a. If m is small we can use trial-and-error to quickly determine a, but in general the value of m might have hundreds of digits (we’re talking about numbers bigger than a trillion times a trillion times a trillion many times over). For this reason, Alice can send the number g a^ (mod m) to Bob and not worry that anyone will figure out her secretly chosen number a, even if they know g, m, and g a^ (mod m). Likewise, Bob can send over g b^ (mod m) and not worry that someone will figure out his secret number b. In this sense, they are sending over their specially-mixed paints and no one can figure out how they mixed them, even if they know that the base was white. At this point Alice still remembers her secret number a and now has a number g b^ (mod m) which she received from Bob. Using this, and modular exponentiation, she can quickly compute (g b^ ) a^ (mod m) by taking g b^ (mod m) to the a th^ power. Likewise, Bob still has his secret number b and also knows g a^ (mod m), which Alice told him, allowing him to compute (g a^ ) b^ (mod m). We might remember from high-school algebra that (x a^ ) b^ = x ab^ = x ba^ = (x b^ ) a^ ; the same rules hold in modular arithmetic, and so (x a^ ) b^ ⌘ x ab^ ⌘ x ba^ ⌘ (x b^ ) a (mod m). Therefore, Alice and Bob now have the same number g ab^ (mod m), and they are the only two people that know the number. Even though bad guys

might know g and m, and even g a^ and g b^ (mod m), they have no way to figure out g ab^ (mod m). If Alice and Bob use g = 3 and modulus m = 19, for example, then if we can just compute g 1 , g 2 ,... , g 18 to determine all possible values of g a^ (mod m), and use that list to determine a once we know g a^ (mod m). As noted above, however, m is usually chosen to be a number with hundreds and hundreds of digits, and calculating a list of possible g a^ (mod m) values for every a < m would take billions and billions of years, even if we had the most powerful computers in the world focused on that problem alone. It is thus the practical impossibility of determining a that makes this protocol secure. We don’t know whether one day someone will figure a way to determine a; if that happens, security as we know it will need new tools. NOTE: In setting up this protocol, it is important to make “good” choices of g and m. To highlight why some thought is necessary, consider choosing g = 10 and m = 101. We might notice quickly notice that g 1 , g 2 , g 3 , g 4 , g 5... ⌘ 10 , 100 , 91 , 1 , 10 ,... (mod 101). In other words, the repeating pattern has pe- riod 4, and so there are only 4 possible values of g n^ (mod 101). That means that Alice and Bob will only be able to send over one of these 4 numbers, making it extremely easy to crack this code.

Example 1. Alice and Bob agree to use g = 7 and m = 997. Alice chooses a = 5 and Bob chooses b = 10; they keep these numbers secret, telling no one else about them. Alice then calculates g a^ = 7 5 ⌘ 855 (mod m) and Bob calculates g b^ = 7^10 ⌘ 224 (mod m). Each sends their computed number to the other, so Alice receives 224 and Bob receives 855. They each then compute g ab (mod 997) by taking their received number and exponentiating it to their secret number. Alice determines that 224 5 ⌘ 455 (mod 997) and Bob determines that 855 10 ⌘ 455 (mod 997). Both Alice and Bob now can use the number 455 as a shared secret password.

Example 2. Alice and Bob agree to use a base g = 37 and modulus m = 2,305,843,009,213,693,951. Alice chooses a = 537 and Bob chooses b = 3024934, which they use to calculate g a^ (mod m) ⌘ 957,141,291,894,918, and g b^ (mod m) = 2,210,741,389,954,762,204. Each sends their computed num- ber to the other, so Alice receives g b^ (mod m) and Bob receives g a^ (mod m). They each then compute g ab^ (mod m) by taking their received number and exponentiating it to their secret number. Alice determines (g b^ ) a^ (mod m) = 2,305,843,009,213,693,951 and Bob determines that (g a^ ) b^ (mod m) is that same number. Alice and Bob now can use this number g ab^ (mod m) as a shared se- cret password to communicate securely. If a bad guy wanted to guess the secret numbers of Alice and Bob, they might need to perform millions of billions of computations to determine that a = 537 or that b = 3024934.

Of course calculating these numbers is not easy to do by hand, but can be done relatively easily by a well-programmed computer. This protocol allows computers to communicate with one another through insecure, public channels, yet protect secrecy of the transmitted information. It is used regularly by billions of electronic devices around the world every single day.