Number Theory and Cryptography
Paul Yiu
Department of Mathematics Florida Atlantic University
Fall 2017
Chapters 9–14
October 23, 2017 ii Contents
5 Quadratic Residues 39 5.1 Quadraticresidues...... 39 5.2 TheLegendresymbol ...... 40 1 5.3 The Legendre symbol −p ...... 41 5.3.1 The square roots of 1 (mod p) ...... 42 5.4 Gauss’lemma ...... − 43 2 5.5 The Legendre symbol p ...... 43 5.6 The law of quadratic reciprocity ...... 44 5.7 Smallest quadratic nonresidue modulo p ...... 47 5.8 Square roots modulo p ...... 48 5.8.1 Square roots modulo prime p 1 (mod 8) ...... 48 5.8.2 Square roots modulo p for a generic6≡ prime p ...... 49 5.9 TheJacobisymbol...... 51
6 Primality Tests and Factorization of Integers 53 6.1 Primality of Mersenne numbers ...... 53 6.2 Germainprimes ...... 55 6.3 Probabilistic primality tests ...... 56 6.3.1 Pseudoprimes...... 56 6.3.2 Euler b-pseudoprimes...... 58 6.3.3 Strong b-pseudoprimes ...... 58 6.4 Carmichaelnumbers...... 61 6.5 Quadratic sieve and factor base ...... 62 6.5.1 Fermat’s factorization ...... 62 6.5.2 Factorbase ...... 63 6.6 Pollard’smethods ...... 66 6.6.1 The ρ-method...... 66 6.6.2 The (p 1)-method ...... 67 − 7 Pythagorean Triangles 69 7.1 Construction of Pythagorean triangles ...... 69 7.2 Fermat’s construction of primitive Pythagorean triangles with con- secutivelegs ...... 70 iv CONTENTS
7.3 Fermat Last Theorem for n =4 ...... 72 7.4 Two ternary trees of rational numbers ...... 73 7.5 Genealogy of Pythagorean triangles ...... 75
8 Homogeneous Quadratic Equations in 3 Variables 79 8.1 Pythagorean triangles revisited ...... 79 8.2 Rational points on a conic ...... 80 8.2.1 Integer triangles with a 60◦ angle ...... 80 8.2.2 Integer triangles with a 120◦ angle...... 82 8.3 Herontriangles...... 84 8.3.1 The Heron formula ...... 84 8.3.2 Construction of Heron triangles ...... 85 8.3.3 Heron triangles with sides in arithmetic progression ..... 86 8.3.4 Heron triangles with integer inradii ...... 87 8.4 The equation Pk,a + Pk,b = Pk,c for polynomial numbers ...... 88 8.4.1 Double ruling of S ...... 89 8.4.2 Primitive Pythagorean triple associated with a k-gonal triple 91 8.4.3 Triangular triples ...... 91 8.4.4 Pentagonal triples ...... 92 38 CONTENTS Chapter 5
Quadratic Residues
5.1 Quadratic residues
Let n > 1 be a given positive integer, and gcd(a,n)=1. We say that a Zn• is a quadratic residue mod n if the congruence x2 a (mod n) is solvable. Otherwise,∈ a is called a quadratic nonresidue mod n. ≡
1. If a and b are quadratic residues mod n, so is their product ab. 2. If a is a quadratic residue, and b a quadratic nonresidue mod n, then ab is a quadratic nonresidue mod n. 3. The product of two quadratic nonresidues mod n is not necessarily a quadratic residue mod n. For example, in Z12• = 1, 5, 7, 11 , only 1 is a quadratic residue; 5, 7, and 11 5 7 are all quadratic{ nonresidues.} ≡ · Proposition 5.1. Let p be an odd prime, and p ∤ a. The quadratic congruence ax2 +bx+c 0 (mod p) is solvable if and only if (2ax+b)2 b2 4ac (mod p) is solvable. ≡ ≡ −
Theorem 5.2. Let p be an odd prime. Exactly one half of the elements of Zp• are quadratic residues.
1 Proof. Each quadratic residue modulo p is congruent to one of the following 2 (p 1) residues. − p 1 2 12, 22, ...,k2, ..., − . 2 p 1 2 2 We show that these residue classes are all distinct. For 1 h < k −2 , h k (mod p) if and only if (k h)(h + k) is divisible by p, this≤ is impossible≤ since≡ each of k h and h + k is smaller− than p. − Corollary 5.3. If p is an odd prime, the product of two quadratic nonresidues is a quadratic residue. 40 Quadratic Residues
In the table below we list, for primes < 50, the quadratic residues and their square roots. It is understood that the square roots come in pairs. For example, the entry (2,7) for the prime 47 should be interpreted as saying that the two solutions of the congruence x2 2 (mod 47) are x 7 (mod 47). Also, for primes of the form p = 4n +1, since≡ 1 is a quadratic≡ residue ± modulo p, we only list quadratic p − p residues smaller than 2 . Those greater than 2 can be found with the help of the square roots of 1. − Quadratic residues mod p and their square roots
3 (1, 1) 5 (−1, 2) (1, 1) 7 (1, 1) (2, 3) (4, 2) 11 (1, 1) (3, 5) (4, 2) (5, 4) (9, 3) 13 (−1, 5) (1, 1) (3, 4) (4, 2) 17 (−1, 4) (1, 1) (2, 6) (4, 2) (8, 5) 19 (1, 1) (4, 2) (5, 9) (6, 5) (7, 8) (9, 3) (11, 7) (16, 4) (17, 6) 23 (1, 1) (2, 5) (3, 7) (4, 2) (6, 11) (8, 10) (9, 3) (12, 9) (13, 6) (16, 4) (18, 8) 29 (−1, 12) (1, 1) (4, 2) (5, 11) (6, 8) (7, 6) (9, 3) (13, 10) 31 (1, 1) (2, 8) (4, 2) (5, 6) (7, 10) (8, 15) (9, 3) (10, 14) (14, 13) (16, 4) (18, 7) (19, 9) (20, 12) (25, 5) (28, 11) 37 (−1, 6) (1, 1) (3, 15) (4, 2) (7, 9) (9, 3) (10, 11) (11, 14) (12, 7) (16, 4) 41 (−1, 9) (1, 1) (2, 17) (4, 2) (5, 13) (8, 7) (9, 3) (10, 16) (16, 4) (18, 10) (20, 15) 43 (1, 1) (4, 2) (6, 7) (9, 3) (10, 15) (11, 21) (13, 20) (14, 10) (15, 12) (16, 4) (17, 19) (21, 8) (23, 18) (24, 14) (25, 5) (31, 17) (35, 11) (36, 6) (38, 9) (40, 13) (41, 16) 47 (1, 1) (2, 7) (3, 12) (4, 2) (6, 10) (7, 17) (8, 14) (9, 3) (12, 23) (14, 22) (16, 4) (17, 8) (18, 21) (21, 16) (24, 20) (25, 5) (27, 11) (28, 13) (32, 19) (34, 9) (36, 6) (37, 15) (42, 18)
5.2 The Legendre symbol
Let p be an odd prime. For an integer a, we define the Legendre symbol
a +1, if a is a quadratic residue mod p, := p 1, otherwise. (−
ab a b Lemma 5.4. p = p p . Proof. This is equivalent to saying that modulo p, the product of two quadratic residues (respectively nonresidues) is a quadratic residue, and the product of a quadratic residue and a quadratic nonresidue is a quadratic nonresidue. 1 5.3 The Legendre symbol −p 41 Theorem 5.5 (Euler). Let p be an odd prime. For each integer a not divisible by p,
a 1 (p 1) a 2 − mod p. p ≡ Proof. Suppose a is a quadratic nonresidue mod p. The mod p residues 1, 2,...,p 1 are partitioned into pairs satisfying xy = a. In this case, −
1 (p 1) (p 1)! a 2 − (mod p). − ≡ On the other hand, if a is a quadratic residue, with a k2 (p k)2 (mod p), ≡ ≡ − apart from 0, k, the remaining p 3 elements of Zp can be partitioned into pairs satisfying xy ±= a. −
1 (p 3) 1 (p 1) (p 1)! k(p k)a 2 − a 2 − (mod p). − ≡ − ≡− Summarizing, we obtain
a 1 (p 1) (p 1)! a 2 − (mod p). − ≡− p Note that by putting a = 1, we obtain Wilson’s theorem: (p 1)! 1 (mod p). a − ≡ − By comparison, we obtain a formula for p : a 1 (p 1) a 2 − (mod p). p ≡
1 5.3 The Legendre symbol −p Theorem 5.6. Let p be an odd prime. 1 is a quadratic residue modulo p if and only if p 1 (mod 4). − ≡ − 2 p 1 p 1 Proof. ( ) If x 1 (mod p), then ( 1) 2 x − 1 (mod p) by Fermat’s ⇒ ≡− p 1 − ≡ ≡ little theorem. This means that −2 is even, and p 1 (mod 4). p 1 ≡ ( ) If p 1 (mod 4), the integer − is even. By Wilson’s theorem, ⇐ ≡ 2 p−1 p−1 p−1 p 1 2 2 2 2 − ! = j2 = j ( j) j (p j)=(p 1)! 1 (mod p). 2 · − ≡ · − − ≡− i=1 i=1 i=1 Y Y Y 2 p 1 The solutions of x 1 (mod p) are therefore x ( − )!. ≡− ≡± 2 Theorem 5.7. There are infinitely many primes of the form 4n +1. 42 Quadratic Residues
Proof. Suppose there are only finitely many primes p1, p2,..., pr of the form 4n+1. Consider the product P = (2p p p )2 +1. 1 2 ··· r Note that P 1 (mod 4). Since P is greater than each of p , p ,..., p , it cannot ≡ 1 2 r be prime, and so must have a prime factor p different from p1, p2, ..., pr. But then modulo p, 1 is a square. By Theorem 5.6, p must be of the form 4n +1,a contradiction. −
5.3.1 The square roots of 1 (mod p) − Here are the square roots of 1 for the first 20 primes p of the form 4k +1: −
p √ 1 p √ 1 p √ 1 p √ 1 p √ 1 − − − − − 5 2 13 5 17 4 29 12 37 6 41 ±9 53 ±23 61 ±11 73 ±27 89 ±34 97 ±22 101 ±10 109 ±33 113 ±15 137 ±37 149 ±44 157 ±28 173 ±80 181 ±19 193 ±81 ± ± ± ± ± In general, the square roots of 1 (mod p) can be found as nk for a quadratic nonresidue n modulo p. −
Example 5.1. Let p = 7933 = 4 1983 + 1. Since p 5 (mod 8), n = 2 is a quadratic nonresidue. We compute×21983 by successive squaring≡ and multiplication making use of the binary expansion
1983 = (11110111111)2.
Since this binary expansion has only one digit 0 at position 26, 1983+26 +20 =211.
a 2 k k ak 2 (mod 7933) 0 1 2 1 1 4 2 1 16 3 1 256 4 1 2072 5 1 1431 6 0 1047 7 1 1455 8 1 6847 9 1 5312 10 1 7596 11 2507 From these, modulo 7933,
2048 1983 2 1 2 = 2507 (2 1047)− 2507 ( 3868) 2950. 2 264 ≡ × × ≡ × − ≡− × The square roots of 1 (mod 7933) are 2950. − ± 5.4 Gauss’ lemma 43
5.4 Gauss’ lemma
Theorem 5.8 (Gauss’ Lemma). Let p be an odd prime, and a an integer not divisible by p. Then a =( 1)µ where µ is the number of residues among p − p 1 a, 2a, 3a,...... , − a 2 p falling in the range 2 r1,r2,...,rλ, and µ negative ones s , s ,..., s . − 1 − 2 − µ p 1 p Here, λ + µ = −2 , and 0 1 (p 1) µ a µ and a 2 − =( 1) . By Theorem 5.5, =( 1) . − p − 2 5.5 The Legendre symbol p Theorem 5.9. Let p be an odd prime. 2 1 (p+1) 1 (p2 1) =( 1)⌊ 4 ⌋ =( 1) 8 − . p − − Equivalently, 2 +1 if p 1 mod 8, = ≡± p 1 if p 3 mod 8. (− ≡± 44 Quadratic Residues Proof. We need to see how many terms in the sequence p 1 2 1, 2 2, 2 3, ..., 2 − · · · · 2 p are in the range 2 5.6 The law of quadratic reciprocity Theorem 5.10 (Law of quadratic reciprocity). Let p and q be distinct odd primes. p q p−1 q−1 =( 1) 2 · 2 . q p − Equivalently, when at least one of p, q 1 mod 4, p is a quadratic residue mod q if and only if q is a quadratic residue mod≡ p. 1 Proof. (1) Let a be an integer not divisible by p. Suppose, as in the proof of Gauss’ p 1 Lemma above, of the residues a, 2a,... −2 a, the positive least absolute value rep- resentatives are r1, r2, ..., rλ, and the negative ones are s1, s2, ..., sµ. The p 1 − − − numbers a, 2a,..., −2 a are a permutation of h a i p + r , i =1, 2, ...,λ, p i and k a j p +(p s ), j =1, 2, ...,µ, p − j p 1 where h1, ..., hλ, k1, ..., kµ are a permutation of 1, 2, . . . , −2 . Considering the sum of these numbers, we have 1 1 (p 1) (p 1) µ 2 − 2 − ma λ a m =p + r + (p s ) · p i − j m=1 m=1 i=1 j=1 X X X X 1For p ≡ q ≡ 3 mod 4, p is a quadratic residue mod q if and only if q is a quadratic nonresidue mod p. 5.6 The law of quadratic reciprocity 45 1 (p 1) µ µ 2 − ma λ =p + r + s + (p 2s ) p i j − j m=1 i=1 j=1 j=1 X X X X 1 1 (p 1) (p 1) µ 2 − ma 2 − =p + m + µ p 2 s . p · − j m=1 m=1 j=1 X X X In particular, if a is odd, then 1 (p 1) 2 − ma µ mod 2, ≡ p m=1 X and by Gauss’ lemma, 1 (p−1) a P 2 ma =( 1) m=1 p . p − ⌊ ⌋ (2) Therefore, for distinct odd primes p and q, we have 1 (p−1) q P 2 mq =( 1) m=1 p , p − ⌊ ⌋ and 1 (q−1) p P 2 np =( 1) n=1 q . q − ⌊ ⌋ q 2 n 2 1 1 2 m p 2 (3) In the diagram above, we consider the lattice points (m,n) with 1 m p 1 q 1 p 1 q 1 ≤ ≤ −2 and 1 n −2 . There are altogether −2 −2 such points forming a ≤ ≤ L · q rectangle. These points are separated by the line of slope p through the point (0,0). p 1 For each m = 1, 2,..., −2 , the number of points in the vertical line through 1 (p 1) (m, 0) under L is mq . Therefore, the total number of points under L is 2 − mq . ⌊ p ⌋ m=1 p P j k 46 Quadratic Residues 1 (q 1) L 2 − np Similarly, the total number of points on the left side of is n=1 q . From these, we have P j k 1 (p 1) 1 (q 1) 2 − mq 2 − np p 1 q 1 + = − − . p q 2 · 2 m=1 n=1 X X It follows that p q p−1 q−1 =( 1) 2 · 2 . q p − The law of quadratic reciprocity can be recast into the following form: q p , if p q 3 mod 4, = − p ≡ ≡ q + q , otherwise. p Example 5.2. (a) 59 is a quadratic residue modulo 131: 59 131 13 59 7 = = = = 131 − 59 − 59 − 13 − 13 13 1 = = − = ( 1)=1. − 7 − 7 − − The square roots are 37. ± (b) 34 is a quadratic nonresidue modulo 97: 34 2 17 2 97 = 97 97 . Now, 97 = +1 by Theorem 5.9, and