# Instructor: Bobby Kleinberg Lecture Notes, 5 May The Miller-Rabin Randomized Primality Test

Save this PDF as:

Size: px
Start display at page:

Download "Instructor: Bobby Kleinberg Lecture Notes, 5 May The Miller-Rabin Randomized Primality Test"

## Transcription

1 Introduction to Algorithms (CS 482) Cornell University Instructor: Bobby Kleinberg Lecture Notes, 5 May 2010 The Miller-Rabin Randomized Primality Test 1 Introduction Primality testing is an important algorithmic problem. In addition to being a fundamental mathematical question, the problem of how to determine whether a given number is prime has tremendous practical importance. Every time someone uses the RSA public-key cryptosystem, they need to generate a private key consisting of two large prime numbers and a public key consisting of their product. To do this, one needs to be able to check rapidly whether a number is prime. The simplest algorithm to test whether n is prime is trial division: for k = 2, 3,..., n test whether n 0 (mod k). This runs in time O( n log 2 (n)), but this running time is exponential in the input size since the input represents n as a binary number with log 2 (n) digits. (A good public key these days relies on using prime numbers with at least binary digits; testing whether such a number is prime using trial division would require at least operations.) In 1980, Michael Rabin discovered a randomized polynomial-time algorithm to test whether a number is prime. It is called the Miller-Rabin primality test because it is closely related to a deterministic algorithm studied by Gary Miller in This is still the most practical known primality testing algorithm, and is widely used in software libraries that rely on RSA encryption, e.g. OpenSSL. 2 Randomized algorithms What does it mean to say that there is a randomized polynomial-time algorithm to solve a problem? Here are some definitions to make this notion precise. Definition 1 (randomized algorithm, RP, corp, BPP). A randomized algorithm for a language L is an algorithm A(x, r) which receives an input string x and a random string r, and attempts to output 1 if x L, 0 if x L. A language L is in RP if there exists a randomized algorithm A(x, r) which runs in time polynomial in x and satisfies: If x L, Pr(A(x, r) = 1) 1/2, when r is randomly sampled from the uniform distribution on {0, 1} r. If x L, A(x, r) = 0 for every r. 1

2 The complexity class corp is defined in the same way except we replace the two conditions with: If x L, A(x, r) = 1 for every r. If x L, Pr(A(x, r) = 0) 1/2. (Equivalently, we could just say L belongs to corp if its complement belongs to RP.) The complexity class BPP is defined in the same way except we replace the two conditions with: If x L, Pr(A(x, r) = 1) 2/3. If x L, Pr(A(x, r) = 0) 2/3. Theorem 1. Definition 1 defines the same complexity classes if we change the constant 1/2 to any constant strictly less than 1, or if we change the constant 2/3 to any constant strictly between 1/2 and 1. In particular, this means that if a language is in any of these complexity classes, there is a randomized polynomial-time algorithm A(x, r) such that for every input x, A(x, r) outputs the correct answer with probability at least So when we discover an efficient randomized algorithm for a problem, it is reasonable to consider that problem to be solved for all practical purposes. The main theorem in this lecture is: Theorem 2. PRIMES is in corp. In other words, there is a randomized test which always outputs prime if its input is prime, and which outputs composite with probability at least 1/2 if its input is composite. However the algorithm may sometimes output prime when its input is actually composite. In 2002, Agrawal, Kayal, and Saxena discovered a deterministic polynomial-time primality test. In other words, they proved PRIMES is in P. While this is a great algorithmic discovery, the Miller-Rabin algorithm is still the most widely used primality testing algorithm (and will probably remain so) because its running time is much faster. 3 Fermat s little theorem, the Fermat test, and Carmichael numbers Theorem 3 (Fermat s little theorem). The number n is prime if and only if the congruence x n 1 1 (mod n) is satisfied for every integer x between 0 and n. 2

3 We will prove the theorem in a series of steps, beginning with: Lemma 4. If p is prime, then every pair of integers a, b satisfies (a + b) p a p + b p (mod p). Proof. By the binomial theorem, (a + b) p = p k=0 ( ) p a k b p k. k Every term in the sum is divisible by p except the k = 0 and k = p terms. Proposition 5. If A is a subset of the integers which is closed under addition and subtraction, then A is equal to dz, the set of all multiples of d, for some integer d. Proof. If A = {0} then d = 0 and we are done. Otherwise, let d be the absolute value of the smallest non-zero element of A. The set A contains all multiples of d, since it contains {±d} and is closed under addition and subtraction. Furthermore, A cannot contain any element x which is not divisible by d, since then we could subtract the nearest multiple of d to obtain a non-zero element of A whose absolute value is less than d. Proof of Fermat s little theorem. If n is not prime then it has a divisor d > 1. The number d n 1 is divisible by d so it is not equal to 1 mod n. If n is prime, let A be the set of integers x which satisfy x n x (mod n). This set contains x = 1, and it is closed under addition and subtraction, by Lemma 4. Hence every integer x belongs to A. Now let x by any integer not divisible by n. The fact that x A means that n x n x = x(x n 1 1). Since n is prime and x is indivisible by n, this implies n x n 1 1, i.e. x n 1 1 (mod n). Definition 2. Let n be a composite number. If n x and x n 1 1 (mod n), we say that x is a Fermat witness for n. If x n 1 1 (mod n) we say x is a Fermat liar for n. Figure 1 describes a primality testing algorithm based on Fermat s little theorem. The idea of the algorithm is simple: pick a positive integers x < n and checking whether x is a Fermat witness. If so, then output composite. Otherwise output prime. To determine whether x is a Fermat witness for n, one needs to compute x n 1 mod n; the obvious way of doing this requires n 2 iterations of mod-n multiplication. But using the binary expansion of n 1 and repeated squaring, we can reduce this to O(log n) multiplication operations. For example, if n = 23 then n 1 = 22 = so x 22 = x 16 x 4 x 2 = (((x 2 ) 2 ) 2 ) 2 (x 2 ) 2 x 2 3

4 FermatTest(n) Choose x {1, 2,..., n 1} uniformly at random. If x n 1 1 (mod n), return composite; Else return probably prime. Figure 1: The Fermat primality test. and this describes an efficient algorithm for raising any integer to the 22nd power. If n is prime, the Fermat primality test will always output probably prime. But if n is composite, the algorithm will not output composite unless it randomly picks a Fermat witness for n. How hard is it to find a Fermat witness? Any proper divisor of n will do, but there may be very few of these. (For example, if n = pq and p, q are distinct primes, the only two proper divisors of n are p and q.) But for most composite numbers, Fermat witnesses are much more prevalent. The next series of lemmas explains why this is so. Lemma 6. Let a, b be any two integers and let d = gcd(a, b). The set az + bz = {ar + bs : r, s Z} is equal to dz where d = gcd(a, b). Proof. The set az + bz is closed under addition and subtraction, so az + bz = cz for some integer c. If d = gcd(a, b) then every element of az + bz is divisible by d, so d c. But a and b are both elements of cz, i.e. they are both divisible by c. This means c is a common divisor of a and b, so c d. It follows that c = d. Lemma 7. If gcd(a, n) = 1 then there is an integer a 1 such that a a 1 1 (mod n). Proof. By Lemma 6, the set az + nz is equal to Z, the set of all integers. In particular, this means there are integers r, s such that ar + ns = 1. This implies that a r 1 (mod n), as desired. Lemma 8. If b, c, n are positive integers such that gcd(c, n) = 1 and the congruence x b c (mod n) has k > 0 solutions, then the congruence x b 1 (mod n) also has k solutions. Proof. Let x 0 be a solution of x b c (mod n). We must have gcd(x 0, n) = 1, since otherwise gcd(x b 0, n) = gcd(c, n) would be greater than 1, contradicting our hypothesis. Lemma 7 now says that there is a number x 1 0 such that x 0 x (mod n). A one-to-one correspondence between the solution sets of x b c (mod n) and of x b 1 (mod n) is given by the mapping y y x 1 0. Corollary 9. If a composite number n has at least one Fermat witness x such that gcd(x, n) = 1, then at least half of the elements of 1, 2,..., n 1 are Fermat witnesses for n. 4

5 Proof. If gcd(x, n) = 1 and x is a Fermat witness for n, then x n 1 c (mod n) for some c 1 satisfying gcd(c, n) = 1. Now we can use Lemma 8 to show that there are at least as many Fermat witnesses as Fermat liars. Definition 3. An odd composite number n is a Carmichael number if every x satisfying gcd(x, n) = 1 is a Fermat liar for n. So far we have established that the Fermat test FermatTest(n) always outputs prime when n is prime, and that it outputs composite with probability at least 1/2 when n is an odd composite number but not a Carmichael number. Obviously, it is easy to test whether an even number is prime. But we still don t have a good algorithm for distinguishing Carmichael numbers from prime numbers. The Miller- Rabin test is a more sophisticated version of the Fermat test which accomplishes this. 4 The Miller-Rabin test So far, we know of two ways to prove that a number n is composite: 1. Exhibit a factorization n = ab, where a, b > Exhibit a Fermat witness for n, i.e. a number x satisfying x n 1 1 (mod n). The Miller-Rabin test is based on a third way to prove that a number is composite. 3. Exhibit a fake square root of 1 mod n, i.e. a number x satisfying x 2 1 (mod n) but x ±1 (mod n). The following lemma explains why this is a satisfactory proof of compositeness. Lemma 10. If x, n are positive integers such that x 2 1 (mod n) but x ±1 (mod n), then n is composite. Proof. The hypotheses of the lemma imply that n is a divisor of x 2 1 = (x+1)(x 1), but n divides neither x + 1 nor x 1. This is impossible when n is prime. Later on, we will need the following generalization of Lemma 10. Lemma 11. If p is prime, then for any k > 0 the number of x {1, 2,..., p 1} satisfying x k 1 (mod p) is at most k. Proof. We will prove, more generally, that for any nonzero polynomial P (x) = a 0 + a 1 x a k x k, the number of x {1, 2,..., p 1} satisfying P (x) 0 (mod p) is at most k. The proof is by induction on k, the base case k = 0 being trivial. Otherwise, suppose a 5

6 MillerRabin(n) If n > 2 and n is even, return composite. /* Factor n 1 as 2 s t where t is odd. */ s 0 t n 1 while t is even s s + 1 t t/2 end /* Done. n 1 = 2 s t. */ Choose x {1, 2,..., n 1} uniformly at random. Compute each of the numbers x t, x 2t, x 4t,..., x 2st = x n 1 mod n. If x n 1 1 (mod n), return composite. for i = 1, 2,..., s If x 2it 1 (mod n) and x 2i 1t ±1 (mod n), return composite. end /* Done checking for fake square roots. */ Return probably prime. Figure 2: The Miller-Rabin primality test. satisfies P (a) 0 (mod p). We may write P (x) = (x a)q(x) + c, where Q(x) is a polynomial of degree k 1 with integer coefficients. The congruence P (a) 0 (mod p) implies that c is divisible by p. If b satisfies P (b) 0 (mod p) but Q(b) 0 (mod p) then p is a divisor of (b a)q(b) but not of Q(b), hence b a (mod p). It follows that every b {1, 2,..., p 1} satisfying P (b) 0 (mod p) satisfies either b = a or Q(b) 0 (mod p). By the induction hypothesis, at most k 1 elements of {1, 2,..., p 1} satisfy the second congruence. The Miller-Rabin test is shown in Figure 2. The idea of the test is to pick a random number x in {1, 2,..., n 1} and use it to try finding either a Fermat witness or a fake square root of 1 mod n. Why does the Miller-Rabin test work? We have seen that when n is prime, the test always outputs probably prime. When n is composite but is not a Carmichael number, we have seen that it outputs composite with probability at least 1/2. What if n is a Carmichael number? The workings of the Miller-Rabin test in this case can best be understood in terms of the Chinese Remainder Theorem. Theorem 12 (Chinese Remainder Theorem). Let n 1, n 2,..., n k be numbers, no two of which have a common factor. For any numbers a 1, a 2,..., a k, the system of con- 6

7 gruences x a 1 (mod n 1 ) x a 2 (mod n 2 ). x a k (mod n k ) has a solution. Any two solutions x 1, x 2 are congruent mod n 1 n 2... n k. Proof. Let m i denote the product of all elements of the set {n 1, n 2,..., n k } other than n i. Note that gcd(m i, n i ) = 1 so Lemma 7 implies that there is a number r i such that m i r i 1 (mod n i ). Now let x = k i=1 a im i r i and check that x satisfies the given system of congruences. If x 1, x 2 both satisfy the given system of congruences, then x 1 x 2 is divisible by each of n 1, n 2,..., n k. As these numbers have no common factors, we may conclude that x 1 x 2 is divisible by n 1 n 2... n k. Corollary 13. Let n = p b 1 1 p b p b k k. Numbers x {1, 2,..., n 1} which are relatively prime to n (i.e. satisfy gcd(x, n) = 1) are in one-to-one correspondence with ordered k-tuples (x 1, x 2,..., x k ) such that 1 x i p b i i 1 and p i x i. Now let s take an example of a Carmichael number and see what happens when we run the Miller-Rabin primality test. The smallest Carmichael number is n = 561 = We have n 1 = 560 = Let s take a random number, e.g. x = 245, and see what happens when we run the algorithm. Number mod 3 mod 11 mod 17 x x x x x x As we read down the numbers in each column, if any entry is equal to 1, then all subsequent entries in that column are also equal to 1. Define the crossover row for column j to be the row in which the number 1 first appears. In order for the Miller-Rabin test to output probably prime, the crossovers must be synchronized, i.e. the crossover row must be the same in each column. We will see that this is an improbable event. To begin with, we need the following description of Carmichael numbers. Lemma 14. If n is a Carmichael number, then n has at least three distinct prime factor and is not divisible by the square of any prime. 7

8 Proof. First suppose that p is prime and p 2 n. Write n = p k q where k > 1 and p q. Using the Chinese Remainder Theorem we may find a number x such that x p + 1 (mod p k ) and x 1 (mod q). We claim that (x, n) = 1 and x is a Fermat witness for n. The fact that (x, n) = 1 is obvious: by construction, x has no common factors with p k or with q, and n = p k q. To see that x n 1 1 (mod n), it suffices to prove that x n 1 1 (mod p 2 ), or equivalently x n x (mod p 2 ). The formula (p + 1) p = p ( p k=0 k) p k implies (p + 1) p 1 (mod p 2 ), which in turn implies x n 1 (mod p 2 ) and, which establishes that x n x (mod p 2 ) as claimed. It remains to prove that when p, q are distinct odd primes, their product n = pq is not a Carmichael number. Assume without loss of generality that p < q. Lemma 11 ensures that there we can choose x {1, 2,..., q 1} such that congruence x p 1 1 (mod q). We claim x is a Fermat witness for n. To prove this, observe that x n 1 = x pq 1 = x pq p x p 1 = (x p ) q 1 x p 1 x p 1 1 (mod q). Since q is a divisor of n, it follows that x n 1 1 (mod n) as claimed. Theorem 15. If n is a Carmichael number, then MillerRabin(n) outputs composite with probability at least 3/4. Proof. Suppose n is a Carmichael number. By analogy with the definitions of Fermat witness and Fermat liar, let us call a number x a Miller-Rabin witness (or MRwitness) for n if the algorithm MillerRabin(n) outputs composite when x is the element of {1, 2,..., n 1} randomly chosen by the algorithm; otherwise we call x a Miller-Rabin liar (or MR-liar) for n. We must prove that there are at most n 1 4 MR-liars. Write n 1 = 2 s t where t is odd. Partition {1, 2,..., n 1} into sets X, Y, Z 1, Z 2,..., Z s defined as follows: x X if x shares a common divisor with n; x Y if x t 1 (mod n). x Z j (1 j s) if x 2jt 1 (mod n) but x 2j 1t 1 (mod n). It is clear that X does not contain any MR-liars. We claim that Y n 1 8 and that each set Z j contains at most Z j /7 MR-liars. Assuming this claim, the total number of MR-liars is at most Y + n 1 Y 7 = 6 Y 7 + n 1 7 6(n 1) n 1 7 = n 1, 4 which will establish the theorem. Suppose n = p 1 p 2... p k is the prime factorization of n; recall from Lemma 14 that k 3 and that the primes p 1,..., p k are all distinct. According to the Chinese Remainder Theorem, choosing a number x {1, 2,..., n 1} \ X is equivalent to 8

9 choosing numbers x i {1, 2,..., p i 1} for each i = 1, 2,..., k. The number x belongs to Y if and only if x t i 1 (mod p i ) for every i. We claim that at most half of the elements y {1, 2,..., p i 1} satisfy y t 1 (mod p i ). Let A i be the set of all integers u such that every y {1, 2,..., p i 1} satisfies y u 1 (mod p i ). This set is closed under addition and subtraction, hence it is equal to dz for some integer d. Moreover, Fermat s Little Theorem ensures that p i 1 A i and Lemma 11 ensures that A i does not contain any number between 0 and p i 1. This implies that A i is the set of all multiples of p i 1; in particular, every element of A i is even and this means that t A i. Thus there is at least one y {1, 2,..., p i 1} satisfying y t 1 (mod p i ), and by Lemma 8 this means that at most half of the elements of {1, 2,..., p i 1} satisfy y t 1 (mod p i ). When we pick elements x i in {1, 2,..., p i 1} uniformly at random, for each i = 1, 2,..., k, the probability that each of these numbers x i satisfies x t i 1 (mod p i ) is at most (1/2) k, which is less than or equal to 1/8 since k 3. Thus the probability that a random x {1, 2,..., n 1} \ X belongs to Y is at most 1/8, which establishes that Y n 1. 8 We turn now to showing that each set Z j contains at most Z j /7 MR-liars. As before, an element x Z j may be represented by a k-tuple of numbers x i {1, 2,..., p i 1}. The fact that x Z j means that x 2j t i 1 (mod p i ) for each value of i. Note that this implies x 2j 1 t i ±1 (mod p i ) for each i, so we can associate to each x Z j a sequence of k +/- signs, with the i-th sign being + or - according to whether x 2j 1 t i +1 or 1 (mod p i ). (The sign sequence is never (+, +,..., +), since this would imply that x Z l for some l < j.) An element x Z j is a MR-liar if and only if its sign sequence is (,,..., ). Let us assume there is at least one MR-liar in Z j ; otherwise there is nothing to prove. If Z j contains a MR-liar, this implies that each of the congruences y 2j 1t 1 (mod p i ) (1 i k) has a solution y i. Let w i be an element of {1, 2,..., n 1} which satisfies w i y i (mod p i ) and w i 1 (mod p i ) for every i i. If σ, σ are two sign sequences which differ only by flipping the i-th sign in the sequence, then multiplication by w i defines a one-to-one correspondence between the set of elements of Z j with sign sequence σ and those with sign sequence σ. It follows that each of the 2 k 1 possible sign sequences defines a subset of Z j whose cardinality is exactly Z j /(2 k 1). In particular, the set of MRliars is defined by the sign sequence (,,..., ) and consequently has cardinality Z j /(2 k 1) Z j /7. Remark 16. Above, we proved that the error probability of MillerRabin(n) is at most 1/4 when n is a Carmichael number. In fact, the error probability is bounded above by 1/4 even when n is not a Carmichael number, though the material in Section 3 established only the weaker bound 1/2. Remark 17. The running time of MillerRabin(n) is O(log 3 n). To see this, recall our earlier observation that it is possible to compute x t (mod n) using O(log n) mod-n multiplication operations. (Each mod-n multiplication takes time O(log 2 n) using the naive algorithms for integer multiplication and division.) Once we have computed 9

10 x t (mod n), the remaining numbers x 2t, x 4t,..., x 2st (mod n) may be obtained by s log 2 (n) iterations of repeated squaring mod n, which again entails only O(log n) mod-n multiplication operations. All the remaining operations in the Miller-Rabin algorithm require much less running time. Remark 18. Miller proved that if one assumes the Extended Riemann Hypothesis (a number-theoretic conjecture generally believed to be true), then for every composite number n the set {1, 2,..., 2 ln 2 (n)} contains a MR-witness for n. Thus, assuming the Extended Riemann Hypothesis, there is a deterministic algorithm to test primality in time O(log 5 n). Without assuming the Extended Riemann Hypothesis, a deterministic primality test with running time O((log n) O(log log log n) ) was discovered in 1983 by Adleman, Pomerance, and Rumely. 5 Epilogue: The AKS primality test For almost 20 years no one made significant further progress toward proving PRIMES is in P. Then in 2002, Agrawal, Kayal, and Saxena proved that PRIMES is in P by discovering a completely different way to prove a number n is composite without using Fermat witnesses or fake square roots of 1. Their algorithm is based on the following theorem. Theorem 19. Let n 2 and a 0 be integers. If n is prime then the polynomials P (x) = (x a) n and Q(x) = x n a are congruent mod n. If n is composite and gcd(a, n) = 1, then P (x) and Q(x) are not congruent mod n. In general, comparing P (x) and Q(x) mod n requires exponential time because it requires enumerating all n coefficients of the polynomials, and n is exponential in the input size. Here, the AKS algorithm uses a clever trick to reduce the work of enumerating coefficients: instead of comparing P (x) and Q(x) mod n, they divide both polynomials by x r 1 (for some value of r which is only polynomial in log(n)) and compare the remainders mod n. The remainders have only r coefficients, and can be efficiently computed without enumerating all the coefficients of P (x) and Q(x). Agrawal, Kayal, and Saxena proved that if n is composite, then one can always find a proof of compositeness by searching exhaustively through pairs of numbers a, r such that both a and r are bounded by some polynomial in log(n). Having found the proper pair a, r, one verifies that the polynomials (x a) n (mod x r 1) and x n a (mod x r 1) are not congruent mod n. Subsequent improvements to the AKS algorithm have brought the running time down to O(log 6 n), still much slower than the O(log 3 n) randomized test presented in this lecture. 10

### Primality - Factorization

Primality - Factorization Christophe Ritzenthaler November 9, 2009 1 Prime and factorization Definition 1.1. An integer p > 1 is called a prime number (nombre premier) if it has only 1 and p as divisors.

### Factoring & Primality

Factoring & Primality Lecturer: Dimitris Papadopoulos In this lecture we will discuss the problem of integer factorization and primality testing, two problems that have been the focus of a great amount

### (x + a) n = x n + a Z n [x]. Proof. If n is prime then the map

22. A quick primality test Prime numbers are one of the most basic objects in mathematics and one of the most basic questions is to decide which numbers are prime (a clearly related problem is to find

### U.C. Berkeley CS276: Cryptography Handout 0.1 Luca Trevisan January, 2009. Notes on Algebra

U.C. Berkeley CS276: Cryptography Handout 0.1 Luca Trevisan January, 2009 Notes on Algebra These notes contain as little theory as possible, and most results are stated without proof. Any introductory

### 9 Modular Exponentiation and Cryptography

9 Modular Exponentiation and Cryptography 9.1 Modular Exponentiation Modular arithmetic is used in cryptography. In particular, modular exponentiation is the cornerstone of what is called the RSA system.

### Lecture 13 - Basic Number Theory.

Lecture 13 - Basic Number Theory. Boaz Barak March 22, 2010 Divisibility and primes Unless mentioned otherwise throughout this lecture all numbers are non-negative integers. We say that A divides B, denoted

### Lecture 13: Factoring Integers

CS 880: Quantum Information Processing 0/4/0 Lecture 3: Factoring Integers Instructor: Dieter van Melkebeek Scribe: Mark Wellons In this lecture, we review order finding and use this to develop a method

### Factoring Algorithms

Factoring Algorithms The p 1 Method and Quadratic Sieve November 17, 2008 () Factoring Algorithms November 17, 2008 1 / 12 Fermat s factoring method Fermat made the observation that if n has two factors

### MODULAR ARITHMETIC. a smallest member. It is equivalent to the Principle of Mathematical Induction.

MODULAR ARITHMETIC 1 Working With Integers The usual arithmetic operations of addition, subtraction and multiplication can be performed on integers, and the result is always another integer Division, on

### Homework until Test #2

MATH31: Number Theory Homework until Test # Philipp BRAUN Section 3.1 page 43, 1. It has been conjectured that there are infinitely many primes of the form n. Exhibit five such primes. Solution. Five such

### Public Key Cryptography: RSA and Lots of Number Theory

Public Key Cryptography: RSA and Lots of Number Theory Public vs. Private-Key Cryptography We have just discussed traditional symmetric cryptography: Uses a single key shared between sender and receiver

### 2.1 Complexity Classes

15-859(M): Randomized Algorithms Lecturer: Shuchi Chawla Topic: Complexity classes, Identity checking Date: September 15, 2004 Scribe: Andrew Gilpin 2.1 Complexity Classes In this lecture we will look

### MATH10040 Chapter 2: Prime and relatively prime numbers

MATH10040 Chapter 2: Prime and relatively prime numbers Recall the basic definition: 1. Prime numbers Definition 1.1. Recall that a positive integer is said to be prime if it has precisely two positive

### The Prime Numbers. Definition. A prime number is a positive integer with exactly two positive divisors.

The Prime Numbers Before starting our study of primes, we record the following important lemma. Recall that integers a, b are said to be relatively prime if gcd(a, b) = 1. Lemma (Euclid s Lemma). If gcd(a,

### Applications of Fermat s Little Theorem and Congruences

Applications of Fermat s Little Theorem and Congruences Definition: Let m be a positive integer. Then integers a and b are congruent modulo m, denoted by a b mod m, if m (a b). Example: 3 1 mod 2, 6 4

### 3. Applications of Number Theory

3. APPLICATIONS OF NUMBER THEORY 163 3. Applications of Number Theory 3.1. Representation of Integers. Theorem 3.1.1. Given an integer b > 1, every positive integer n can be expresses uniquely as n = a

### Elementary Number Theory We begin with a bit of elementary number theory, which is concerned

CONSTRUCTION OF THE FINITE FIELDS Z p S. R. DOTY Elementary Number Theory We begin with a bit of elementary number theory, which is concerned solely with questions about the set of integers Z = {0, ±1,

### Homework 5 Solutions

Homework 5 Solutions 4.2: 2: a. 321 = 256 + 64 + 1 = (01000001) 2 b. 1023 = 512 + 256 + 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = (1111111111) 2. Note that this is 1 less than the next power of 2, 1024, which

### MATH 289 PROBLEM SET 4: NUMBER THEORY

MATH 289 PROBLEM SET 4: NUMBER THEORY 1. The greatest common divisor If d and n are integers, then we say that d divides n if and only if there exists an integer q such that n = qd. Notice that if d divides

### 8 Primes and Modular Arithmetic

8 Primes and Modular Arithmetic 8.1 Primes and Factors Over two millennia ago already, people all over the world were considering the properties of numbers. One of the simplest concepts is prime numbers.

### SUBGROUPS OF CYCLIC GROUPS. 1. Introduction In a group G, we denote the (cyclic) group of powers of some g G by

SUBGROUPS OF CYCLIC GROUPS KEITH CONRAD 1. Introduction In a group G, we denote the (cyclic) group of powers of some g G by g = {g k : k Z}. If G = g, then G itself is cyclic, with g as a generator. Examples

### CS 103X: Discrete Structures Homework Assignment 3 Solutions

CS 103X: Discrete Structures Homework Assignment 3 s Exercise 1 (20 points). On well-ordering and induction: (a) Prove the induction principle from the well-ordering principle. (b) Prove the well-ordering

### Math 319 Problem Set #3 Solution 21 February 2002

Math 319 Problem Set #3 Solution 21 February 2002 1. ( 2.1, problem 15) Find integers a 1, a 2, a 3, a 4, a 5 such that every integer x satisfies at least one of the congruences x a 1 (mod 2), x a 2 (mod

### International Journal of Information Technology, Modeling and Computing (IJITMC) Vol.1, No.3,August 2013

FACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDED Omar Akchiche 1 and Omar Khadir 2 1,2 Laboratory of Mathematics, Cryptography and Mechanics, Fstm, University of Hassan II Mohammedia-Casablanca,

### Notes on Factoring. MA 206 Kurt Bryan

The General Approach Notes on Factoring MA 26 Kurt Bryan Suppose I hand you n, a 2 digit integer and tell you that n is composite, with smallest prime factor around 5 digits. Finding a nontrivial factor

### Discrete Mathematics, Chapter 4: Number Theory and Cryptography

Discrete Mathematics, Chapter 4: Number Theory and Cryptography Richard Mayr University of Edinburgh, UK Richard Mayr (University of Edinburgh, UK) Discrete Mathematics. Chapter 4 1 / 35 Outline 1 Divisibility

### Discrete Mathematics Lecture 3 Elementary Number Theory and Methods of Proof. Harper Langston New York University

Discrete Mathematics Lecture 3 Elementary Number Theory and Methods of Proof Harper Langston New York University Proof and Counterexample Discovery and proof Even and odd numbers number n from Z is called

### Integer Factorization using the Quadratic Sieve

Integer Factorization using the Quadratic Sieve Chad Seibert* Division of Science and Mathematics University of Minnesota, Morris Morris, MN 56567 seib0060@morris.umn.edu March 16, 2011 Abstract We give

### I. GROUPS: BASIC DEFINITIONS AND EXAMPLES

I GROUPS: BASIC DEFINITIONS AND EXAMPLES Definition 1: An operation on a set G is a function : G G G Definition 2: A group is a set G which is equipped with an operation and a special element e G, called

### Computing exponents modulo a number: Repeated squaring

Computing exponents modulo a number: Repeated squaring How do you compute (1415) 13 mod 2537 = 2182 using just a calculator? Or how do you check that 2 340 mod 341 = 1? You can do this using the method

### Number Theory. Proof. Suppose otherwise. Then there would be a finite number n of primes, which we may

Number Theory Divisibility and Primes Definition. If a and b are integers and there is some integer c such that a = b c, then we say that b divides a or is a factor or divisor of a and write b a. Definition

### CHAPTER 5. Number Theory. 1. Integers and Division. Discussion

CHAPTER 5 Number Theory 1. Integers and Division 1.1. Divisibility. Definition 1.1.1. Given two integers a and b we say a divides b if there is an integer c such that b = ac. If a divides b, we write a

### Breaking The Code. Ryan Lowe. Ryan Lowe is currently a Ball State senior with a double major in Computer Science and Mathematics and

Breaking The Code Ryan Lowe Ryan Lowe is currently a Ball State senior with a double major in Computer Science and Mathematics and a minor in Applied Physics. As a sophomore, he took an independent study

### Cryptography and Network Security Chapter 8

Cryptography and Network Security Chapter 8 Fifth Edition by William Stallings Lecture slides by Lawrie Brown (with edits by RHB) Chapter 8 Introduction to Number Theory The Devil said to Daniel Webster:

### Continued Fractions and the Euclidean Algorithm

Continued Fractions and the Euclidean Algorithm Lecture notes prepared for MATH 326, Spring 997 Department of Mathematics and Statistics University at Albany William F Hammond Table of Contents Introduction

### APPLICATIONS OF THE ORDER FUNCTION

APPLICATIONS OF THE ORDER FUNCTION LECTURE NOTES: MATH 432, CSUSM, SPRING 2009. PROF. WAYNE AITKEN In this lecture we will explore several applications of order functions including formulas for GCDs and

### MA257: INTRODUCTION TO NUMBER THEORY LECTURE NOTES

MA257: INTRODUCTION TO NUMBER THEORY LECTURE NOTES 2016 47 4. Diophantine Equations A Diophantine Equation is simply an equation in one or more variables for which integer (or sometimes rational) solutions

### THE MATHEMATICS OF PUBLIC KEY CRYPTOGRAPHY.

THE MATHEMATICS OF PUBLIC KEY CRYPTOGRAPHY. IAN KIMING 1. Forbemærkning. Det kan forekomme idiotisk, at jeg som dansktalende og skrivende i et danskbaseret tidsskrift med en (formentlig) primært dansktalende

### CLASS 3, GIVEN ON 9/27/2010, FOR MATH 25, FALL 2010

CLASS 3, GIVEN ON 9/27/2010, FOR MATH 25, FALL 2010 1. Greatest common divisor Suppose a, b are two integers. If another integer d satisfies d a, d b, we call d a common divisor of a, b. Notice that as

### RSA and Primality Testing

and Primality Testing Joan Boyar, IMADA, University of Southern Denmark Studieretningsprojekter 2010 1 / 81 Correctness of cryptography cryptography Introduction to number theory Correctness of with 2

### The application of prime numbers to RSA encryption

The application of prime numbers to RSA encryption Prime number definition: Let us begin with the definition of a prime number p The number p, which is a member of the set of natural numbers N, is considered

### Is n a Prime Number? Manindra Agrawal. March 27, 2006, Delft. IIT Kanpur

Is n a Prime Number? Manindra Agrawal IIT Kanpur March 27, 2006, Delft Manindra Agrawal (IIT Kanpur) Is n a Prime Number? March 27, 2006, Delft 1 / 47 Overview 1 The Problem 2 Two Simple, and Slow, Methods

### Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University http://www.cs.stonybrook.

Elementary Number Theory and Methods of Proof CSE 215, Foundations of Computer Science Stony Brook University http://www.cs.stonybrook.edu/~cse215 1 Number theory Properties: 2 Properties of integers (whole

### Fractions and Decimals

Fractions and Decimals Tom Davis tomrdavis@earthlink.net http://www.geometer.org/mathcircles December 1, 2005 1 Introduction If you divide 1 by 81, you will find that 1/81 =.012345679012345679... The first

### PYTHAGOREAN TRIPLES PETE L. CLARK

PYTHAGOREAN TRIPLES PETE L. CLARK 1. Parameterization of Pythagorean Triples 1.1. Introduction to Pythagorean triples. By a Pythagorean triple we mean an ordered triple (x, y, z) Z 3 such that x + y =

### Public Key Cryptography and RSA. Review: Number Theory Basics

Public Key Cryptography and RSA Murat Kantarcioglu Based on Prof. Ninghui Li s Slides Review: Number Theory Basics Definition An integer n > 1 is called a prime number if its positive divisors are 1 and

### SUM OF TWO SQUARES JAHNAVI BHASKAR

SUM OF TWO SQUARES JAHNAVI BHASKAR Abstract. I will investigate which numbers can be written as the sum of two squares and in how many ways, providing enough basic number theory so even the unacquainted

### Winter Camp 2011 Polynomials Alexander Remorov. Polynomials. Alexander Remorov alexanderrem@gmail.com

Polynomials Alexander Remorov alexanderrem@gmail.com Warm-up Problem 1: Let f(x) be a quadratic polynomial. Prove that there exist quadratic polynomials g(x) and h(x) such that f(x)f(x + 1) = g(h(x)).

### Principles of Public Key Cryptography. Applications of Public Key Cryptography. Security in Public Key Algorithms

Principles of Public Key Cryptography Chapter : Security Techniques Background Secret Key Cryptography Public Key Cryptography Hash Functions Authentication Chapter : Security on Network and Transport

### V55.0106 Quantitative Reasoning: Computers, Number Theory and Cryptography

V55.0106 Quantitative Reasoning: Computers, Number Theory and Cryptography 3 Congruence Congruences are an important and useful tool for the study of divisibility. As we shall see, they are also critical

### Finite Fields and Error-Correcting Codes

Lecture Notes in Mathematics Finite Fields and Error-Correcting Codes Karl-Gustav Andersson (Lund University) (version 1.013-16 September 2015) Translated from Swedish by Sigmundur Gudmundsson Contents

### MATH 537 (Number Theory) FALL 2016 TENTATIVE SYLLABUS

MATH 537 (Number Theory) FALL 2016 TENTATIVE SYLLABUS Class Meetings: MW 2:00-3:15 pm in Physics 144, September 7 to December 14 [Thanksgiving break November 23 27; final exam December 21] Instructor:

### 2 Primality and Compositeness Tests

Int. J. Contemp. Math. Sciences, Vol. 3, 2008, no. 33, 1635-1642 On Factoring R. A. Mollin Department of Mathematics and Statistics University of Calgary, Calgary, Alberta, Canada, T2N 1N4 http://www.math.ucalgary.ca/

### 11 Ideals. 11.1 Revisiting Z

11 Ideals The presentation here is somewhat different than the text. In particular, the sections do not match up. We have seen issues with the failure of unique factorization already, e.g., Z[ 5] = O Q(

### Lecture 3: Finding integer solutions to systems of linear equations

Lecture 3: Finding integer solutions to systems of linear equations Algorithmic Number Theory (Fall 2014) Rutgers University Swastik Kopparty Scribe: Abhishek Bhrushundi 1 Overview The goal of this lecture

### An Overview of Integer Factoring Algorithms. The Problem

An Overview of Integer Factoring Algorithms Manindra Agrawal IITK / NUS The Problem Given an integer n, find all its prime divisors as efficiently as possible. 1 A Difficult Problem No efficient algorithm

### 8 Divisibility and prime numbers

8 Divisibility and prime numbers 8.1 Divisibility In this short section we extend the concept of a multiple from the natural numbers to the integers. We also summarize several other terms that express

### RSA Question 2. Bob thinks that p and q are primes but p isn t. Then, Bob thinks Φ Bob :=(p-1)(q-1) = φ(n). Is this true?

RSA Question 2 Bob thinks that p and q are primes but p isn t. Then, Bob thinks Φ Bob :=(p-1)(q-1) = φ(n). Is this true? Bob chooses a random e (1 < e < Φ Bob ) such that gcd(e,φ Bob )=1. Then, d = e -1

### Lectures on Number Theory. Lars-Åke Lindahl

Lectures on Number Theory Lars-Åke Lindahl 2002 Contents 1 Divisibility 1 2 Prime Numbers 7 3 The Linear Diophantine Equation ax+by=c 12 4 Congruences 15 5 Linear Congruences 19 6 The Chinese Remainder

### CONTINUED FRACTIONS AND FACTORING. Niels Lauritzen

CONTINUED FRACTIONS AND FACTORING Niels Lauritzen ii NIELS LAURITZEN DEPARTMENT OF MATHEMATICAL SCIENCES UNIVERSITY OF AARHUS, DENMARK EMAIL: niels@imf.au.dk URL: http://home.imf.au.dk/niels/ Contents

### Quotient Rings and Field Extensions

Chapter 5 Quotient Rings and Field Extensions In this chapter we describe a method for producing field extension of a given field. If F is a field, then a field extension is a field K that contains F.

### Introduction to finite fields

Introduction to finite fields Topics in Finite Fields (Fall 2013) Rutgers University Swastik Kopparty Last modified: Monday 16 th September, 2013 Welcome to the course on finite fields! This is aimed at

### Primes in Sequences. Lee 1. By: Jae Young Lee. Project for MA 341 (Number Theory) Boston University Summer Term I 2009 Instructor: Kalin Kostadinov

Lee 1 Primes in Sequences By: Jae Young Lee Project for MA 341 (Number Theory) Boston University Summer Term I 2009 Instructor: Kalin Kostadinov Lee 2 Jae Young Lee MA341 Number Theory PRIMES IN SEQUENCES

### k, then n = p2α 1 1 pα k

Powers of Integers An integer n is a perfect square if n = m for some integer m. Taking into account the prime factorization, if m = p α 1 1 pα k k, then n = pα 1 1 p α k k. That is, n is a perfect square

### ALGEBRAIC APPROACH TO COMPOSITE INTEGER FACTORIZATION

ALGEBRAIC APPROACH TO COMPOSITE INTEGER FACTORIZATION Aldrin W. Wanambisi 1* School of Pure and Applied Science, Mount Kenya University, P.O box 553-50100, Kakamega, Kenya. Shem Aywa 2 Department of Mathematics,

### Mathematics for Computer Science/Software Engineering. Notes for the course MSM1F3 Dr. R. A. Wilson

Mathematics for Computer Science/Software Engineering Notes for the course MSM1F3 Dr. R. A. Wilson October 1996 Chapter 1 Logic Lecture no. 1. We introduce the concept of a proposition, which is a statement

### Introduction to Finite Fields (cont.)

Chapter 6 Introduction to Finite Fields (cont.) 6.1 Recall Theorem. Z m is a field m is a prime number. Theorem (Subfield Isomorphic to Z p ). Every finite field has the order of a power of a prime number

### Recent Breakthrough in Primality Testing

Nonlinear Analysis: Modelling and Control, 2004, Vol. 9, No. 2, 171 184 Recent Breakthrough in Primality Testing R. Šleževičienė, J. Steuding, S. Turskienė Department of Computer Science, Faculty of Physics

### Notes for Recitation 5

6.042/18.062J Mathematics for Computer Science September 24, 2010 Tom Leighton and Marten van Dijk Notes for Recitation 5 1 Exponentiation and Modular Arithmetic Recall that RSA encryption and decryption

### Integers and division

CS 441 Discrete Mathematics for CS Lecture 12 Integers and division Milos Hauskrecht milos@cs.pitt.edu 5329 Sennott Square Symmetric matrix Definition: A square matrix A is called symmetric if A = A T.

Primes, Factoring, and RSA A Return to Cryptography Foundations of Cryptography Computer Science Department Wellesley College Table of contents Introduction Generating Primes RSA Assumption A classic hard

### CONTRIBUTIONS TO ZERO SUM PROBLEMS

CONTRIBUTIONS TO ZERO SUM PROBLEMS S. D. ADHIKARI, Y. G. CHEN, J. B. FRIEDLANDER, S. V. KONYAGIN AND F. PAPPALARDI Abstract. A prototype of zero sum theorems, the well known theorem of Erdős, Ginzburg

### = 2 + 1 2 2 = 3 4, Now assume that P (k) is true for some fixed k 2. This means that

Instructions. Answer each of the questions on your own paper, and be sure to show your work so that partial credit can be adequately assessed. Credit will not be given for answers (even correct ones) without

### The Prime Facts: From Euclid to AKS

The Prime Facts: From Euclid to AKS c 2003 Scott Aaronson 1 Introduction My idea for this talk was to tell you only the simplest, most basic things about prime numbers the things you need to know to call

### The cyclotomic polynomials

The cyclotomic polynomials Notes by G.J.O. Jameson 1. The definition and general results We use the notation e(t) = e 2πit. Note that e(n) = 1 for integers n, e(s + t) = e(s)e(t) for all s, t. e( 1 ) =

### GCDs and Relatively Prime Numbers! CSCI 2824, Fall 2014!

GCDs and Relatively Prime Numbers! CSCI 2824, Fall 2014!!! Challenge Problem 2 (Mastermind) due Fri. 9/26 Find a fourth guess whose scoring will allow you to determine the secret code (repetitions are

### On the generation of elliptic curves with 16 rational torsion points by Pythagorean triples

On the generation of elliptic curves with 16 rational torsion points by Pythagorean triples Brian Hilley Boston College MT695 Honors Seminar March 3, 2006 1 Introduction 1.1 Mazur s Theorem Let C be a

### Lecture 2: Universality

CS 710: Complexity Theory 1/21/2010 Lecture 2: Universality Instructor: Dieter van Melkebeek Scribe: Tyson Williams In this lecture, we introduce the notion of a universal machine, develop efficient universal

### Section 6-2 Mathematical Induction

6- Mathematical Induction 457 In calculus, it can be shown that e x k0 x k k! x x x3!! 3!... xn n! where the larger n is, the better the approximation. Problems 6 and 6 refer to this series. Note that

### Lecture 1: Course overview, circuits, and formulas

Lecture 1: Course overview, circuits, and formulas Topics in Complexity Theory and Pseudorandomness (Spring 2013) Rutgers University Swastik Kopparty Scribes: John Kim, Ben Lund 1 Course Information Swastik

### Cryptography and Network Security Number Theory

Cryptography and Network Security Number Theory Xiang-Yang Li Introduction to Number Theory Divisors b a if a=mb for an integer m b a and c b then c a b g and b h then b (mg+nh) for any int. m,n Prime

### PROBLEM SET 6: POLYNOMIALS

PROBLEM SET 6: POLYNOMIALS 1. introduction In this problem set we will consider polynomials with coefficients in K, where K is the real numbers R, the complex numbers C, the rational numbers Q or any other

### The Chinese Remainder Theorem

The Chinese Remainder Theorem Evan Chen evanchen@mit.edu February 3, 2015 The Chinese Remainder Theorem is a theorem only in that it is useful and requires proof. When you ask a capable 15-year-old why

### Arithmetic algorithms for cryptology 5 October 2015, Paris. Sieves. Razvan Barbulescu CNRS and IMJ-PRG. R. Barbulescu Sieves 0 / 28

Arithmetic algorithms for cryptology 5 October 2015, Paris Sieves Razvan Barbulescu CNRS and IMJ-PRG R. Barbulescu Sieves 0 / 28 Starting point Notations q prime g a generator of (F q ) X a (secret) integer

### PYTHAGOREAN TRIPLES KEITH CONRAD

PYTHAGOREAN TRIPLES KEITH CONRAD 1. Introduction A Pythagorean triple is a triple of positive integers (a, b, c) where a + b = c. Examples include (3, 4, 5), (5, 1, 13), and (8, 15, 17). Below is an ancient

### 5.1 Commutative rings; Integral Domains

5.1 J.A.Beachy 1 5.1 Commutative rings; Integral Domains from A Study Guide for Beginner s by J.A.Beachy, a supplement to Abstract Algebra by Beachy / Blair 23. Let R be a commutative ring. Prove the following

### The last three chapters introduced three major proof techniques: direct,

CHAPTER 7 Proving Non-Conditional Statements The last three chapters introduced three major proof techniques: direct, contrapositive and contradiction. These three techniques are used to prove statements

### Integers, Division, and Divisibility

Number Theory Notes (v. 4.23 October 31, 2002) 1 Number Theory is the branch of mathematics that deals with integers and their properties, especially properties relating to arithmetic operations like addition,

### SECTION 10-2 Mathematical Induction

73 0 Sequences and Series 6. Approximate e 0. using the first five terms of the series. Compare this approximation with your calculator evaluation of e 0.. 6. Approximate e 0.5 using the first five terms

### Algebraic and Transcendental Numbers

Pondicherry University July 2000 Algebraic and Transcendental Numbers Stéphane Fischler This text is meant to be an introduction to algebraic and transcendental numbers. For a detailed (though elementary)

### On the largest prime factor of x 2 1

On the largest prime factor of x 2 1 Florian Luca and Filip Najman Abstract In this paper, we find all integers x such that x 2 1 has only prime factors smaller than 100. This gives some interesting numerical

### Revised Version of Chapter 23. We learned long ago how to solve linear congruences. ax c (mod m)

Chapter 23 Squares Modulo p Revised Version of Chapter 23 We learned long ago how to solve linear congruences ax c (mod m) (see Chapter 8). It s now time to take the plunge and move on to quadratic equations.

### COMS4236: Introduction to Computational Complexity. Summer 2014

COMS4236: Introduction to Computational Complexity Summer 2014 Mihalis Yannakakis Lecture 17 Outline conp NP conp Factoring Total NP Search Problems Class conp Definition of NP is nonsymmetric with respect

### Today s Topics. Primes & Greatest Common Divisors

Today s Topics Primes & Greatest Common Divisors Prime representations Important theorems about primality Greatest Common Divisors Least Common Multiples Euclid s algorithm Once and for all, what are prime

### 1 Definition of a Turing machine

Introduction to Algorithms Notes on Turing Machines CS 4820, Spring 2012 April 2-16, 2012 1 Definition of a Turing machine Turing machines are an abstract model of computation. They provide a precise,

### Elementary Number Theory

Elementary Number Theory A revision by Jim Hefferon, St Michael s College, 2003-Dec of notes by W. Edwin Clark, University of South Florida, 2002-Dec L A TEX source compiled on January 5, 2004 by Jim Hefferon,

### Some practice problems for midterm 2

Some practice problems for midterm 2 Kiumars Kaveh November 15, 2011 Problem: What is the remainder of 6 2000 when divided by 11? Solution: This is a long-winded way of asking for the value of 6 2000 mod

### Chapter 3. if 2 a i then location: = i. Page 40

Chapter 3 1. Describe an algorithm that takes a list of n integers a 1,a 2,,a n and finds the number of integers each greater than five in the list. Ans: procedure greaterthanfive(a 1,,a n : integers)