Introduction to Cryptography

Similar documents
Homework Problems, Math 134, Spring 2007 (Robert Boltje)

Lemma 1.2. (1) If p is prime, then ϕ(p) = p 1. (2) If p q are two primes, then ϕ(pq) = (p 1)(q 1).

Public Key Cryptography

Basic elements of number theory

Basic elements of number theory

Lecture 5: Arithmetic Modulo m, Primes and Greatest Common Divisors Lecturer: Lale Özkahya

CIS 551 / TCOM 401 Computer and Network Security

Candidates must show on each answer book the type of calculator used. Only calculators permitted under UEA Regulations may be used.

ECE596C: Handout #11

Mathematics of Cryptography

ICS141: Discrete Mathematics for Computer Science I

Cryptography. P. Danziger. Transmit...Bob...

Encryption: The RSA Public Key Cipher

Introduction to Modern Cryptography. Benny Chor

Mathematics for Cryptography

CRYPTOGRAPHY AND NUMBER THEORY

Notes 10: Public-key cryptography

CPSC 467b: Cryptography and Computer Security

Discrete Mathematics GCD, LCM, RSA Algorithm

CPE 776:DATA SECURITY & CRYPTOGRAPHY. Some Number Theory and Classical Crypto Systems

Introduction to Public-Key Cryptosystems:

Number Theory. Modular Arithmetic

Applied Cryptography and Computer Security CSE 664 Spring 2018

A Guide to Arithmetic

Elementary Number Theory MARUCO. Summer, 2018

CS483 Design and Analysis of Algorithms

Integers and Division

Addition. Ch1 - Algorithms with numbers. Multiplication. al-khwārizmī. al-khwārizmī. Division 53+35=88. Cost? (n number of bits) 13x11=143. Cost?

Simple Math: Cryptography

9 Knapsack Cryptography

Number Theory: Applications. Number Theory Applications. Hash Functions II. Hash Functions III. Pseudorandom Numbers

YALE UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE

Mathematical Foundations of Cryptography

Discrete mathematics I - Number theory

CODING AND CRYPTOLOGY III CRYPTOLOGY EXERCISES. The questions with a * are extension questions, and will not be included in the assignment.

The RSA cryptosystem and primality tests

1 Recommended Reading 1. 2 Public Key/Private Key Cryptography Overview RSA Algorithm... 2

Lecture Notes, Week 6

CPSC 467b: Cryptography and Computer Security

Cryptography. pieces from work by Gordon Royle

CPSC 467b: Cryptography and Computer Security

10 Modular Arithmetic and Cryptography

10 Public Key Cryptography : RSA

MODULAR ARITHMETIC KEITH CONRAD

CPSC 467: Cryptography and Computer Security

Number theory (Chapter 4)

Week 7 An Application to Cryptography

Chapter 8 Public-key Cryptography and Digital Signatures

Course 2BA1: Trinity 2006 Section 9: Introduction to Number Theory and Cryptography

} has dimension = k rank A > 0 over F. For any vector b!

Number Theory Notes Spring 2011

Elementary Number Theory Review. Franz Luef

Number Theory. CSS322: Security and Cryptography. Sirindhorn International Institute of Technology Thammasat University CSS322. Number Theory.

RSA. Ramki Thurimella

Public Key Algorithms

Security Issues in Cloud Computing Modern Cryptography II Asymmetric Cryptography

CS March 17, 2009

2. Cryptography 2.5. ElGamal cryptosystems and Discrete logarithms

Know the Well-ordering principle: Any set of positive integers which has at least one element contains a smallest element.

Chapter 5. Number Theory. 5.1 Base b representations

Lecture 1: Introduction to Public key cryptography

MATH 145 Algebra, Solutions to Assignment 4

An Introduction to Cryptography

Introduction to Modern Cryptography. Benny Chor

Notes. Number Theory: Applications. Notes. Number Theory: Applications. Notes. Hash Functions I

Topics in Cryptography. Lecture 5: Basic Number Theory

8.1 Principles of Public-Key Cryptosystems

Number Theory A focused introduction

Mathematical Foundations of Public-Key Cryptography

Public-Key Encryption: ElGamal, RSA, Rabin

3 The fundamentals: Algorithms, the integers, and matrices

4 Number Theory and Cryptography

NUMBER THEORY. Anwitaman DATTA SCSE, NTU Singapore CX4024. CRYPTOGRAPHY & NETWORK SECURITY 2018, Anwitaman DATTA

W3203 Discrete Mathema1cs. Number Theory. Spring 2015 Instructor: Ilia Vovsha. hcp://

University of Regina Department of Mathematics & Statistics Final Examination (April 21, 2009)

Clock Arithmetic and Euclid s Algorithm

Course MA2C02, Hilary Term 2013 Section 9: Introduction to Number Theory and Cryptography

Lecture notes: Algorithms for integers, polynomials (Thorsten Theobald)

MATH3302 Cryptography Problem Set 2

2 More on Congruences

2.3 In modular arithmetic, all arithmetic operations are performed modulo some integer.

ASSIGNMENT Use mathematical induction to show that the sum of the cubes of three consecutive non-negative integers is divisible by 9.

ECEN 5022 Cryptography

Public-Key Cryptosystems CHAPTER 4

Fall 2017 September 20, Written Homework 02

My brief introduction to cryptography

Univ.-Prof. Dr. rer. nat. Rudolf Mathar. Written Examination. Cryptography. Tuesday, August 29, 2017, 01:30 p.m.

Introduction to Cybersecurity Cryptography (Part 5)

during transmission safeguard information Cryptography: used to CRYPTOGRAPHY BACKGROUND OF THE MATHEMATICAL

Classical Cryptography

download instant at

MATH 158 FINAL EXAM 20 DECEMBER 2016

Public Key Encryption

CPSC 467: Cryptography and Computer Security

CPSC 467b: Cryptography and Computer Security

Cryptography and Network Security Prof. D. Mukhopadhyay Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

CPSC 467b: Cryptography and Computer Security

Know the meaning of the basic concepts: ring, field, characteristic of a ring, the ring of polynomials R[x].

Number Theory and Algebra: A Brief Introduction

LECTURE 5: APPLICATIONS TO CRYPTOGRAPHY AND COMPUTATIONS

Transcription:

Introduction to Cryptography Hong-Jian Lai West Virginia University, Morgantown, WV 26506-6310 Version 2007 March 2, 2007 TABLE OF CONTENTS I. Divisibility............................................................................. 1 II. Congruences.......................................................................... 5 III. Numbers in Different Bases.......................................................... 13 IV. Encryption and Decryption, Classical Cryptosystems...................................15 V. Some Linear Algebra over Z m, Enciphering Matrices................................... 17 VI. Public Key Cryptosystems........................................................... 23 VII. The Primarity Test and Factorization................................................ 27 VIII. RSA Algorithm.................................................................... 36 IX. Discrete Logarithm.................................................................. 38 X. Digital Signature..................................................................... 44 XI. Elliptic Curves...................................................................... 47 Appendix 1: Equivalence Relations....................................................... 55 Appendix 2: Measure of Difficulty........................................................ 56 1. Divisibility 1.1 Notation: Let Z denote the set of all integers and let N denote the set of all positive integers. For a, b Z, write a b if d Z such that b = ad; and we say a is a divisor of b and b is a multiple of a. If a is not a divisor of b, we write a b. If 1 < a < b and if a b, then a is a nontrivial divisor of b. An integer p N is a prime if b > 1 and b has no nontrivial divisors. Note that 0 zero is not a divisor of any nonzero number and that 0 is a multiple of any integer. On the other hand, 1 one is a divisor of any integer. 1

1.1A Exercise: Suppose that a, b, c Z, show that each of the following holds. i If a b, then a bc. ii If a b and if b c, then a c. iii If a b and if a c, then a b ± c. 1.2 Fundamental Theorem of Arithmetic: Let n N with n > 1. Then each of the following holds. A existence of factorization There exist primes p 1, p 2,, p m and natural numbers α 1, α 2,, α m N such that n = p α 1 1 pα 2 2 pαm m. B uniqueness of factorization If there are primes q 1, q 2,, q s and natural numbers β 1, β 2,, β s N such that n = q β 1 1 qβ 2 2 qβs s, then m = s and there is a permutation π on the set {1, 2,, m} such that q πi = p i and β πi = α i. 1.2 Another way of stating the Fundamental Theorem of Arithmetics: i Every positive integer other than 1 is product of primes. ii This factorization into primes is unique, up to a permutation of the factors. Remark: As a traditional convenience, we view a single number n as a product with only one factor. In plain language, any natural number n N can be written uniquely except for the order of factors as a product of prime numbers. Example: 2520 = 2 3 3 2 57. 1.2A Exercise: If p is a prime, a, b Z, and if p ab, then either p a or p b. 1.3 Given a, b Z such that one of them is nonzero, the greatest common divisor of a and b, denoted by a, b, or by gcda, b is the largest integer d such that d a and d b; the least common multiple of a and b, denoted by [a, b], is the smallest positive integer m such that a m and b m. 1.3A Exercise: Show that for any integer a, b Z, [a, b]a, b = ab. 1.3B Exercise: Let a, b Z {0}. Then a, b = a, b. Similarly, [a, b] = [ a, b]. 1.3C Exercise: Suppose that a, c = 1. If a bc, then a b. 1.3D Exercise: Let n N be an integer and let φn be the number of integers m such that 1 m < n and such that n, m = 1. For example, φ1 = φ2 = 1, φ3 = φ4 = φ6 = 2. In general, one can easily show that if p is a prime, then φp = p 1. Show that if n = pq for two distinct primes p and q, then φn = p 1q 1. Let U p be the set of positive 2

multiples of p not bigger than n and U q be the set of positive multiples of q not bigger than n. Then U p U q = {n} and U p = q, U q = p. Thus φn = pq U p U q +1 = p 1q 1. 1.3E Exercise: More generally, show that if n, m N and if n, m = 1, then φnm = φnφm. 1.3R Remark: The notation n, m is traditionally abused. It is here used to denote the greatest common divisor of n and m. It will later be used to mean a 2-dimensional vector in Section 5, and an ordered pair of enciphering or deciphering keys Section 6. It is some what lucky for us not to use any open intervals in this lecture note. However, I think the reader should have no confusion from the context what this notation will mean, and when confusion is likely to occur, we will use gcda, b. 1.4 The Division Division For any n Z and d N, there are unique integers q Z and r N such that n = dq + r and such that 0 r < d. q is the quotient and r is the remainder of the division. Example: n = 1547 and d = 560, then q = 2 and r = 427. 1.5 The Euclidean Algorithm: Objective: Find a, b for given a, b Z. Input: a, b with a > b > 0. Initialization: n := a, d := b. Iteration: Apply Long division to n and d to find n = dq + r, as described in 1.4. IF r = 0, then STOP: the current value d is a, b. OTHERWISE set n := d and d := r, and repeat the iteration. 1.5 Another way of stating the Euclidean Algorithm: Input: Positive integers a and b with a b. The Algorithm: Repeatedly apply integer division if needed to obtain the following: a = bq 1 + r 1 0 r 1 < b b = q 2 r 1 + r 2 0 r 2 < r 1 r 1 = q 3 r 2 + r 3 0 r 3 < r 2... r k 2 = q k r k 1 + r k 0 r k < r k 1 r k 1 = q k+1 r k Output: a, b = r k. If r 1 = 0, then a, b = b. 3

1.5A Example: Find 1547,560. 1547 = 2560 + 427 560 = 427 + 133 427 = 3133 + 28 133 = 428 + 21 28 = 21 + 7 21 = 37 + 0, 7 = 211547 2560 16560 = 211547 58560 7 = 5427 16560 427 = 21427 16560 7 = 5427 3133 133 = 5427 16133 7 = 28 133 + 428 = 528 133 7 = 28 21. At the last interation left column, n = 21, d = 7, q = 3 and r = 0. Thus 1547,560=7. The right column will be used in 1.5D. 1.5B Exercise: Find 1428, 847. 1.5C Exercise: Show that given a, b Z {0}, there exist u, v Z such that ua+vb = a, b. Hint: Revise the Algorithm 1.5 to find these u and v. 1.5D Example: 1547,560 = 21 1547 + -58560. 1.5E Exercise: Show that given a, b Z {0}, a, b is the smallest positive integer that can be written in the form ua + vb for some integers u, v Z. Hint: Let d be the smallest positive integer that can be written in the form ua + vb for some integers u, v Z. Then d = ua + vb for certain u, v Z. Ask these questions: if d is a common divisor of d, must d d?; is d a common divisor of a and b? 1.5F Exercise: If for some integers u and v such that ua + vb = 1, then a, b = 1. Hint: use 1.5E. 1.5G Summary of Elementary Properties of gcd Let a and b be two integers with a + b > 0, and let d = a, b. i There exist integers s and t such that d = as + bt. ii a and b are relatively prime if and only if there exist integers s and t such that 1 = as+bt. iii Suppose d = a, b. Then a/d, b/d = 1. iv If a, b = 1, then [a, b] = ab. Remark: Therefore when a, b = 1, any common multiple of a and b is also a multiple of ab. This property will be used in 3.1 below. v ab = a, b[a, b]. 1.5H Exercise: Explain why Algorithm 1.5 can give you the right answer. 4

2. Congruences 2.1 Notation: Given a, b Z and m N, if m a b, then we write a b mod m or a m b and say that a is congruent to b modulo m. 2.1A Examples: 4 3 7; 14 2 mod 4. 2.1B Exercise: Show m is an equivalence relation. 2.2 a m b if and only if there is an integer k such that a = b + km. 2.3 Properties Let a, b, c, d, m be integers with m 0. i a m 0 if and only if m a. ii a m a. iii a m b if and only if b m a. iv If a m b and if b m c, then a n c. v If a m b and c m d, then a + c m b + d, a c m b d, ac bd. Remark: Apply 2.1 and 2.2 to prove all these properties. Property 2.3v says that for addition, subtraction and multiplication, modulo n can be done just like those for integers. 2.3A Exercise: For fixed m N, show that each equivalence class of m has one and only one member in the set {0, 1,, m 1}. Notation: The set of all equivalence classes called residue classes will be denoted by Z m. We shall write Z m = { 0, 1,, m 1}, where ī denotes the equivalence class with i as a representative. 2.3B Exercise: Find Z 7. 2.3C Exercise: Show that if a m b and c m d, then a ± c m b ± d and ac m bd. 2.3D Exercise: If c, m = 1, and if ac m bc, then a m b. Hint: Apply 1.3C. 2.3E Exercise: Find an example such that one may have ac m bc but not a m b. 5

2.4 Notation If ab m 1, then ā and b are inverse residue classes of each other. If ā has an inverse residue class, then by writing ā 1 in Z m we mean the n-th power of the inverse residue class or just inverse for short of ā in Z m. 2.5 Conditional Division Let a, b, c, d, m be integers with n m and with a, m = 1. If ab m ac, then b m c. That is, if a, m = 1, then we can divide both sides by a modulo m. Proof: Apply 2.2. 2.5A Exercise: Find the inverse of 2 in Z 7, and write the fraction 3 2 in Z 7 as a member in Z 7. Can you find the inverse of 2 in Z 4? 2.5B Example: 2 4 7 4 4 7 4, since 24 7 1. 2.5C Exercise: Show that if ā has an inverse in Z m, then the inverse is unique. In other words, if b and c are inverses of ā in Z m, then b = c. Hint: If ab m 1 m ac, then b m c. 2.5D Exercise: Show that ā has an inverse in Z m iff a, m = 1. 2.6 Exercise: If p is a prime, then every element in Z p has an inverse. Therefore one can do the usual arithmetic for numbers in Z p except the outcome must be modulo p. The Z p with the arithmetic addition and multiplication modulo p is called a field, or the field of p elements. 2.7 Summary of Some Basic Skills: i Skill 1 Finding a 1 mod m. This can be done only when a, m = 1. Step 1 Apply Euclidean Algorithm to find s and t so that as + mt = 1. Step 2 as m 1, that is, s m a 1. ii Skill 2 Solving equation ax m c when a, m = 1. Step 1 Find s m a 1. Step 2 Multiply a 1 to both sides of the equation to get x m a 1 c m cs. iii Skill 3 Solving equation ax m c when a, m > 1. Step 1 Compute d = a, m. If d b, then ax m b has no solution. Step 2 Suppose d b. Let a 1 = a/d, b 1 = b/d and m 1 = m/d. Then by 1.7, a 1, m 1 = 1, and so we can apply Skill 2 to find a solution x 0 for the equation a 1 x m1 b 1. Step 3 The complete set of solutions of the equation ax m b is then obtained as x 0, x 0 + m 1, x 0 + 2m 1,, x 0 + d 1m 1 mod m. 6

2.7A Example. Solve the equation 3x 6 mod 15. Solution: Here d = 3, 15 = 3. As 3 6, we reduce the equation to x 2mod5. Then we have a solution x 0 = 2 in Z 5. Then in Z 15, we have these solutions d = 3 of them: 2, 2 + 5 = 7, 2 + 10 = 12. 2.8 Given integers a and b with d = a, b, how to find integers x and y such that ax + by = d? Consider the case when d = 1 first. When d > 1, consider the equation a b x + y = 1, d d instead. Use Euclidean Algorithm and Exercise 1.5C. 2.9 Chinese Remainder Theorem: Two Equation Form Let m, n be integers with m, n = 1. Given integers a and b, there exists exactly one solution x mod mn to the simultaneous congruences { x m a, x n b. Existence of x As m, n = 1, we can apply Euclidean Algorithm to find integers s and t so that ms + nt = 1. Thus x = bms + ant satisfies both x m a and x n b. Uniqueness of x modulo mn Let x 1 be another solution. Then x x 1 m 0 and x x 1 n 0. Thus m x x 1 and n x x 1. Thus mn x x 1. 2.9A Example: Solve x 2 mod 4 and x 5 mod 7. Note that 4, 7 = 1, and in fact, 54 + 37 = 1. Thus x = 54 5 + 273 = 100 + 42 = 58 28 2 28 26. 2.10 Chinese Remainder Theorem: General Form Let m 1, m 2, m k be integers with m i, m j = 1 whenever i j. Given integers a 1, a 2,, a k, there exists exactly one solution x mod m 1 m 2 m k to the simultaneous congruences x m1 a 1, x m2 a 2,. x mk a k. 7

2.11 Algorithm Computing the unique solution guaranteed by the Chinese Remainder Theorem Step 1 Set m := m 1 m 2 m k and for i = 1, 2,, k, set z i := m/m i. Step 2 For i = 1, 2,, k, compute y i mi z 1 i. Step 3 The solution x = a 1 y 1 z 1 + a 2 y 2 z 2 + + a k y k z k. 2.11A Example: Solve for x in the system x 1 mod 11 x 1 mod 13 x 1 mod 17. Solution: Here, a 1 = 1, a 2 = 1, a 3 = 1, and m 1 = 11, m 2 = 13 and m 3 = 17. Apply the algorithm. Step 1 Set m = m 1 m 2 m 3 = 11 13 17 = 2431, and z 1 = 13 17 = 221, z 2 = 11 17 = 187 and z 3 = 11 13 = 143. Step 2 For i = 1, as 11, 221 = 1 = 2011 + 1221, y 1 z 1 1 1 mod 11. For i = 2, as 13, 187 = 1 = 7213 + 5187 = 936 935, y 2 z 1 2 5 mod 13. For i = 3, as 17, 143 = 1 = 4217 + 5143 = 714 + 715, y 3 z 1 3 5 mod 17. Step 3 A solution of the system is x = 11221 + 1 5187 + 15143 = 221 + 935 + 715 = 1871. As 0 < 1871 < 2431 = m, this solution is unique modulo 2431. 2.12 Fermat s Little Theorem: Let p be a prime and let a Z. Then each of these holds: i a p p a or write it another way: a p a mod p. ii If p a, then a p 1 p 1. Proof: It suffices to show that case when p a. By 2.4, az p = Z p as a set. Multiply the nonzero elements in these two sets to get a p 1 p 1! p p 1!. Then by 2.3D, a p 1 p 1. 2.12A Exercise: What happens when p a in the proof of 2.12? of 2.12. Give a detailed proof 8

2.12B Exercise: Suppose that p is a prime and p a. If n p 1 m, then a n p a m. Hint: Assume n > m. Note that p 1 n m, or n = m + cp 1. Thus a n p a m+cp 1 and so one can apply 2.12. 2.12C Exercise: Find the remainder of 2 1000000 when divided by 7. Hint: 1000000 = 1666666 + 4. 2.13 Computational Properties of φn φn = n p n 1 1 p where the product is over the distinct prime factors of n. In particular, we have, when p and q are primes with p, q = 1 and k > 0 is an integer, i φp = p 1. ii φp k = p k p k 1. iii φpq = p 1q 1. 2.14 Euler s Theorem If a, n = 1, then a φn n 1. 2.15 Modular Exponentiation Let a, n, x, y be integers with n > 0 and a, n = 1. If x φn y, then a x n a y. 2.16 Modular Exponentiation Algorithm For positive integers a, x and n, this algorithm computes a x mod n. Step 1 Initialization: Set A := x, B := 1 and C := a. Step 2 If A is even, let A := A/2, B := B and C : n C 2. Step 3 If A is odd, let A : A 1, B : n BC and C := C. Step 4 If A 0, GOTO Step 2. Step 5 Output B = a x mod n. 2.17 Let n be a positive integer. If r is such an integer that the powers of r produces all the nonzero congruence classes modulo n, then r is a primitive root modulo n or for the integer n. In other words, r is primitive root modulo n if and only if the sequence r, r 2, r 3,, r n 1 has n 1 distinct elements in Z n. Example: p = 7 and r = 3. 9

2.17A Note that if r is a primitive root modulo n, then r, n = 1. 2.17B For a fixed r and n such that r, n = 1, for a given x, an integer l is a discrete logarithm of x base r modulo n if r l x mod n. 2.17C Find primitive root modulo p = 11. 2.18 Let r be a primitive root mod p. i For any 0 < k < p 1, r k p 1 but r p 1 p 1. ii If n is an integer, then r n p 1 if and only if n p 1 0. iii If j and k are integers, then r j p r k if and only if j p 1 k. Proof: i By Fermat s little theorem, r p 1 p 1. Suppose that for some 0 < k < p 1, r k p 1. Then r k+1 p r, and so the sequence r 1, r 2, r p 1, has at most p 2 distinct elements in Z p {0}, and so r is not primitive. ii Suppose that r n p 1. Write n = qp 1 + b with 0 b < p 1. Then 1 p r n p r qp 1+b p r b. Since 0 b < p 1, and by i, b = 0. Conversely, suppose that n p 1 0. Then n = qp 1 for some integer q. Thus by Fermat s little theorem, r n p 1. iii Suppose that r i p r k. 1 p r j r k p r j k. By ii, j k p 1 0, or j p 1 k. 2.19 Example: For a prime p > 0, solve x 2 p 1. Suppose that for some ā Z p such that a 2 p 1. Then p a 2 1 and so p a 1 or p a + 1. Thus x = 1 or x = p 1. 2.19A Example: Solve for x in x 2 1 mod 21. 5pt] Solution: Note that 21 = 37. As x 2 1 0 mod 21 37 x 2 1 either 3 x 2 1 or 7 x 2 1, the equation x 2 1 mod 21 is equivalent to the system { x 2 1 mod 3 x 2 1 mod 7. Since both 3 and 7 are primes, x 2 1 1 mod 3 has solutions x = ±1 and x 2 1 mod 7 has solutions x = ±1. Apply the Chinese Remainder Theorem Algorithm and consider all 10

4 possible combinations of solutions: x 3 1 and x 7 1 = x 21 1 x 3 1 and x 7 1 = x 21 13 x 3 1 and x 7 1 = x 21 13 x 3 1 and x 7 1 = x 21 1 Therefore, the solutions for the equation are 1, 8, 13 and 20 modulo 21. 2.19B Example: Solve for x in x 2 133 mod 143. 5pt] Solution: Note that 143 = 1113. As x 2 133 0 mod 143 1113 x 2 133 either 11 x 2 133 or 13 x 2 133, the equation x 2 133 mod 143 is equivalent to the system { x 2 133 mod 11 x 2 133 mod 13. Since both 11 and 13 are primes, x 2 133 1 mod 11 has solutions x = ±1 and x 2 133 3 16 mod 13 has solutions x = ±4. Apply the Chinese Remainder Theorem Algorithm and consider all 4 possible combinations of solutions: x 11 1 and x 13 4 = x 143? x 11 1 and x 13 4 = x 143? x 11 1 and x 13 4 = x 143? x 11 1 and x 13 4 = x 143? Therefore, the solutions for the equation are x 143 56, 43, 100, 87, respectively. 2.20 Example: Solve x 2 15 1. Try all the elements in Z 15 to find that x = 1, 4, 11, 14 are all the solutions. 2.21 Partial Solution of x 2 m b. Let p 4 3 be a prime and let y be an integer, and y 0 4 y p+1/4. Then i If x 2 p y has an integral solution, then the solutions must be ±y 0 mod p. ii If x 2 p y has no integral solutions, then ±y 0 mod p are the solutions of the equation x 2 p y. 2.22 Matrix Inversion Mod n Let M be a matrix whose entries are in Z n such that detm n 0. Let M 1 denote the inverse of M over the reals R. Then the inverse of M in Z n can be obtained from M 1 by taking each entry of M 1 mod n. 11

2.23 The field GF 4 = GF 2 2. GF 4 = {0, 1, ω, ω + 1}. The addition and multiplication can be done as the elements are polynomials in ω over Z 2, subject to ω 2 = ω + 1. Therefore, if we replace the symbol ω by another symbol x, then GF 4 is Z 2 [x] modulo x 2 + x + 1. 2.24 In general, if F is a field, and if px is an irreducible polynomial in F [x], then F [x] modulo px is a field in which every non zero element has an inverse. 2.25 The field GF 2 8. This is Z 2 [x] modulo x 8 + 8x 4 + x 3 + x 2 + x + 1. 12

3. Numbers in Different Bases 3.1 Fix an integer b N. A natural number n N written to the base b is a notation for n of the form d k 1 d k 2 d 1 d 0 b, where the d s are symbols for the integers between 0 and b 1 called the digits; this notation means that n = d k 1 b k 1 + d k 2 b k 2 + + d 1 b + d 0. The notation d k 1 d k 2 d 1 d 0 b is called a base-b representation of n. When d k 1 0, n is a k-digit base-b number. Traditionally, we write d k 1 d k 2 d 1 d 0 for d k 1 d k 2 d 1 d 0 10. 3.1A Example: Base-2 numbers are also called binary numbers. A k-digit base-2 number is also called a k-bit number, where the word bit is short for binary digit. A byte is an 8-bit number. ASCII, American Standard Code for Information Interchange, is a way to represent characters using 7-bit numbers. Thus 1011 2 is a 4-bit number, which represents the integer 11 since 1101 2 = 2 3 + 2 2 + 1 = 13. of a positive num- 3.1B Exercise: What is the base-1 representation of the number 4? ber n? What is the base-b representation of the number 0? 3.2 Any English word with k letters can be viewed as a k-digit base-26 number. with A Z representing the digits 0-25, respectively. A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 We can also use decimal point here as we are doing for base-10 integers. Therefore, BAD 26 = 26 2 + 3 = 676 + 3 = 679, whereas B.AD 26 = 1 + 3 = 1 3 26 2 676. When there is no confusion arises, we shall omit the subscript 26 in this representation of numbers. Hence BAD = 679 and B.AD = 1 3 676 = B D BAA. 3.2A Exercise: Divide 11001001 2 by 100111 2 Answer: 101 110 100111 3.2B Exercise: Divide HAP P Y by SAD Answer: KD MLP SAD. in base-2. 3.2c Exercise: Convert 1000 to base-2 and base-26 using letters A Z. Solution: To convert a number n to base b, one can use division 1.4 to find the reminder when n is divided by b, this reminder r will then be the last digit in the base-b representation of n. Hence one can use the following algorithm in 3.3 to find: 100 = 1100100 2 = DW. 13

3.3 Converting Base-10 to Base-b Algorithm: We assume b > 1. See 3.1B for the case when b = 1. Input: The integers n > 0 and b > 1. Output: base-b representation of n. When the algorithm halts, it will output the base-b representation of n: d k 1 d k 2 d 1 d 0 b. Note that K = k 1 in the algorithm. Initialization: N := n, K := 0, d 0 := N. Iteration: If N < b, then d 0 b is the base-b representation of n. Otherwise do the following: Apply 1.4. Divide N by b to get quotient q and remainder r. Set d k := r; N := q and K := K + 1. Repeat the iteration. 3.3A Example: 100 = 250 + 0, 50 = 225 + 0, 25 = 212 + 1, 12 = 26 + 0, 6 = 23 + 0, 3 = 2 + 1, 1 = 0 + 1. Thus 100 = 1100100 2. 3.3B Example: 100 = 326 + 22 and so 100 = DW. 3.3C Multiply Y ES by NO. Divide W V U by MAT H. 3.3D Multiply 101101 2 and 11001 2. 3.3E Exercise: The hexadecimal system means b = 16 with A F representing the tenth through fifteenth digits, respectively. Divide 131B6C3 16 by 1A2F 16. 3.3F Exercise: Explain how to convert back and forth between binary and hexadecimal representations of an integer. Describe an algorithm to perform such conversions. 3.3G Exercise: Fix a natural number b > 2. Explain how to convert back and forth between binary and base-b representations of an integer. Describe an algorithm to perform such conversions. 3.3H Exercise: Explain why Algorithm 3.3 gives you the correct answer. 14

4. Encryption and Decryption, Classical Cryptosystems 4.1 Notation: The message we want to send is called plain text and the disguised message is called cipher text. Both the plain text and the cipher text are written in some alphabet consisting of N letters of characters, which could be the usual letters A Z, or numbers, or any other symbols, even blanks. The process of converting a plain text into a cipher text is called encryption and the reverse process is called decryption. The set of all plain text message units is denoted by P and the set of all cipher text is denoted by C. The whole process can be represented schematically by P C P. Any such setup is called a cryptosystem or just a cipher, in which the function f : P C is the enciphering function or the enciphering transformation, whereas its inverse function f 1 : C P is the deciphering function or the deciphering transformation. Note that any enciphering function must be a bijection. 4.1A Example: Let P = Z 26, which in turn represents the usual English alphabet A Z. Define f : P P by, P P, { P + 3 if 0 P < 23, fp = P 23 if 23 P 25. Then this defines a cryptosystem Why?. For example: Y ES = 24418 1721 = BHV Y ES. 4.1B Exercise: Use the cryptosystem in 4.1A to decode ZKB. Answer: W HY. 4.2 The Caesar s Cipher also called the shift cipher: Let the alphabet be one with N letters with numerical equivalents 0, 1,, N 1. Let b N be a fixed integer, and let C = fp N P + b be the enciphering function. Then this defines a cryptosystem. Why? What is the deciphering function? The parameter b is called the enciphering key. 4.2A Example of Code Breaking by Frequency Analysis: Under the assumption that the letter E is the most frequently occurring letter in English this comes from statistics, and that Julius Caesar s Cryptosystem is used, one can pickup the most frequent occurring character in the intercepted message to find the enciphering key. Example : Assume that in the intercepting message, U occurs most frequently, and that part of the message is IUDT CEDUO. Then if E = 4 becomes E + b = U = 20, then in Z 26, b = 16. Therefore, IUDT CEDUO = 8203192432014 184133121413424 = SENDMONEY 15

4.2B Exercise: Break the code by using the method in 4.2A: IUUOEKRUSAO. Answer: SEEY OU BECKY. 4.3 An affine cryptosystem uses the enciphering function C = fp = ap + b mod N. The ordered pair a, b here is the enciphering key. 4.3A Exercise: Encipher SENDMONEY by the affine cryptosystem with a = 7, b = 12 and N = 26. 4.3B Exercise: Encipher the answer in 4.2B by the affine cryptosystem with a = 7, b = 12 and N = 26. 4.3C Exercise: Show that in order for the function f in 4.3 to be an enciphering function, one must have a, N = 1. In this case, f 1 C = a 1 C + a 1 b mod N. 4.3D Exercise: Is affine cipher always a good one? Consider the situation that you have just received a coded message ERRER, instructing you to do something to a given data set. Assuming that you have already known the encoding system is an affine cipher with a = 13, b = 4 and N = 26. Can you decode this instruction? What happens if someone sends you both the message INPUT and ALTER to you using this cipher? 4.4 Digraph transformation. Message units can be represented by ordered pairs of letters called digraphs. Each digraph x, y is then assigned a numerical equivalent. The usual way of this assignment is x, y xn + y, where N is the number of letters in the alphabet. This represents the digraph x, y as a 2-digit base-n number. Note that x, y xn + y is a bijection between the set of all digraphs in the N-letter alphabet and the set of {0, 1, 2,, N 2 1}, or the 2-dimensional vector space Z 2 N. 4.4A Example: With N = 26 and the digraph enciphering transformation C 26 2 159P + 580, the message NO becomes QY. In this cipher, the key is the ordered pair 159, 580. Reason: NO 1326+14 = 352, 159352+580 = 55968+580 = 56548 = 83676+440 676 440, and 440 = 1626 + 24 = QY. 4.4B Exercise: What does ON become with the same enciphering function in 4.4A? 4.4C Exercise: How to break a digraph cryptosystem? Any idea? 16

4.4D Remark: An ordered pair can viewed as a vector in Z 2 N, where vector addition and scalar multiplication are clearly defined in the usual way. Since in general Z N is only a commutative ring with unity, Z 2 N is usually called a Z N-module. A Z N -module becomes a vector space only when Z N is a field, that is, when N is a prime. 4.5 The k-graphs. Extending the thought of a digraph, one can represent a message unit by a k-tuple with entries in Z N. Often, a k-tuple x k 1, x k 2,, x 0 ZN k may be viewed as a k-digit base-n number x k 1 x k 2 x 1 x 0 N, which means x k 1 N k 1 + + x 1 N + x 0. 4.5A Example: Let N = 26. base 10-number answer: To encode Y ES into a 3-graph, one can do this with a Y ES = 24418 26 2426 2 + 426 + 18 = 16346. 17

5. Some Linear Algebra Over Z m, Enciphering Matrices 5.1 Notation: M 2 Z m denotes the set of all 2 by 2 matrices over Z m. One can add, subtract and multiply two matrices in M 2 Z m and still end up with a matrix there. The elements in Z m with a multiplicative inverse form a set Z m, which is a multiplicative abelian group. By 2.5D, Z m = {ī : i, m = 1}. 5.1A Example: The inverse of the matrix 2 3 17 24 A = M 2 Z 27 is A 1 =. 2 17 25 2 a b 5.1B Exercise: Let m N be an integer. Given a matrix A = M 2 Z m, the c d following are equivalent: i A has an inverse. ii ad bc, m = 1. The value deta = ad bc is called the determinant of A. iii If x 0 Z 2 m, then Ax 0. iv The map fx = Ax is a bijection from Z 2 m onto itself. Find a for- 5.1C Exercise: Assume that one of the conclusions listed in 5.1B holds. mula to compute A 1 in this case. 5.1D Exercise: Find the inverse of A in M 2 Z 5, where A = 1 3 4 2. 5.1E Exercise: Solve the system in Z 9 : { x + 4y = 1 5x + 7y = 1. 5.2 Enciphering Matrices: Let A be an invertible matrix. The map defined in 5.1Biv defines an enciphering transformation, and the matrix A is the enciphering key. 5.2A Example: Work with the 27-letter alphabet where the letters A Z have numerical 2 3 equivalents 0 25, and blank =26. Let A =. Then the message NO ANSW ER 2 17 can be viewed as 5 2-letter units: NO, A, NS, W E, R. Note that the blank between O and A counts. Note also that a blank is added after R to make the number of characters even. Thus the message has numerical equivalent view each unit as a column vector: 13 26 13 22 17 P =. 14 0 18 4 26 18

Thus the enciphered message becomes: C = AP = 2 3 2 17 13 26 13 22 17 14 0 18 4 26 = 14 25 26 2 4 21 25 8 4 17 = OV ZZ ICEER. 5.2B Exercise: Use the same alphabet and the same matrix A as in 5.2A to decode the ciphertext: V XF SJQOQHW SE. Answer: SEE Y OU BECKY. Note that the blanks inside the message and after BECKY count. This comes from the following computation: 17 3 2 2 21 5 9 10 14 7 18 23 18 16 23 16 12 4 = 18 4 24 20 1 2 24 4 26 14 26 4 10 26. 5.3 An example of Code Breaking: We shall use the 26-letter alphabet A Z. We intercept the ciphertext W KNCCHSSJH and we have learned that the first word is GIV E. To break the code, we need to find the deciphering matrix A 1. Let P = GIV E = 6 21 8 4, C = W KNC = 22 13 10 2, and A 1 = P C 1. However, detc = 18 and so by 5.1B, C 1 does not exist. To resolve this problem, we let A 1, P 1 and C 1 be the matrices of A, P, and C in Z 13, respectively. Then as A A 1 mod 13, we have A 1 A 1 1 mod 13, and so we can write A 1 = A 1 1 + 13A 0, for some A 0 M 2 Z 2. Taking modulo 13 both sides of C = AP to get C 1 = A 1 P 1, and so C = 22 13 10 2 13 9 0 10 2 = A 1 6 8 8 4 = A 1 P 1 13 A 6 21 8 4. Here C 1 = 9 0 10 2 and P 1 = 6 8 8 4. As detc 1 = 18 13 5, and as 5 1 13 8. The inverse of C 1 exists as using 10 13 3 Therefore over Z 13, C 1 1 = A 1 1 = P 1 C 1 1 = 9 0 10 2 6 8 8 4 1 13 8 3 0 11 7 2 0 3 9 = 13 3 0 11 7 18 + 88 56 24 + 44 28. 13 2 4 3 2. 19

Note that A 1 A 1 1 mod 13. As the entries in A 1 are elements in Z 26, and as these entries are now reduced in A 1 1 to elements in Z 13, it follows that 2 4 A 1 = + 13A 0, 3 2 where A 0 M 2 Z 2. There are 2 4 = 16 matrices in M 2 Z 2. As A 1 should be invertible to be a deciphering key, the determinant of A 1 should be relatively prime to 26, and in particular, relatively prime to 2. In other words, deta 1 should be an odd integer. We may assume that A 0 = x11 x 12 x 21 x 22, where each x ij Z 2. The fact that the determinant of A 1 should be an odd integer becomes which gives, in modulo 2, 2 + 13x 11 2 + 13x 22 4 + 13x 12 3 + 13x 21 1 mod 2, deta 1 x 11 x 22 x 12 1 + x 21 1 mod 2. There are only 6 possibilities of the values of A 0 such that this would be satisfied. We determine these possibilities, as follows. Determining A 0. Case 1: x 11 = 0. To get deta 1 2 1, we must have x 12 = 1 and x 21 = 0. However, x 22 can be either 0 or 1. Thus these are possible candidates for A 0 : 0 1 0 0 or 0 1 0 1 Case 2: x 11 = 1 and x 22 = 0. To get deta 1 2 1, we must have x 12 = 1 and x 21 = 0. Thus this is a possible candidate for A 0 : 1 1 0 0.. Case 3: x 11 = 1, x 22 = 1, and x 12 = 1. To get deta 1 2 1, we must have x 21 = 1. Thus this is a possible candidate for A 0 : 1 1 1 1. 20

Case 4: x 11 = 1, x 22 = 1, and x 12 = 0. It does not matter if x 21 = 0 or x 21 = 1, we always have get deta 1 2 1. Thus these are possible candidates for A 0 : 1 0 1 1 or 1 0 0 1 To further reduce the number of possibilities for A 0, we take modulo 2 both sides of 0 1 P = A 1 C for each of these six possibilities of A 0. As an example, for A 0 =, we 0 0 should have 0 1 0 0 P A 1 C a contradiction. Thus A 0 0 0 1 0 0 1 0 0 these six possibilities, only 1 0 1 1 will satisfy the equation A 1 C = P mod 2. + 0 1 0 0. 0 1 0 0 0 0 0 1 mod 2. Similarly, we can exclude three others. Thus among and 1 1 1 1 5.3A Exercise: Substituting these six possible A 0 into A 1 and use A 1 C = P in M 2 Z 26 to show that the possibilities for A 0 can be reduced to the following two A 0 = 1 0 1 1 or 1 1 1 1. It follows that A 1 = 15 4 16 15 or 15 17 16 15. The first choice of A 1 yields the decoded message GIV EGHEMHP, which does not sound right. However, the second one gives GIV ET HEMUP, and so it must be the correct one. FACT: There are 175,248 invertible matrices in M 2 Z 26. 5.3B Exercise: You intercepted the message!iwgviex!zradryd. You know that a linear enciphering transformation is being used with a 29-letter alphabet, in which A-Z have numerical equivalents 0-25, blank = 26,? = 27,! = 28. You further know that the last five letters of the plaintext are MARIA Find the deciphering matrix A 1 and the full plaintext message. 21

5.3C Exercise: You intercepted the message KVW? TA!KJB?FVR. The blanks after? and R are part of the message, but the final. is not. You know that a linear enciphering transformation is being used with a 30-letter alphabet, in which A-Z have numerical equivalents 0-25, blank = 26,? = 27,! = 28,.=29. You further know that the first six letters of the plaintext are C.I.A. Find the deciphering matrix A 1 and the full plaintext message. 22

6. Public Key Cryptography 6.1 Terminology: The letter b of the enciphering functions in 4.2, the pair a, b of the enciphering functions in 4.3, and the entries of the enciphering matrices in Section 5 regarded as components of a vector, are called the enciphering keys, and is denoted by K E. The corresponding parameters in the deciphering functions and matrices are the deciphering keys and denoted by K D. If the deciphering process takes about the same or similar level of difficulty as in the enciphering process, such a cryptosystem will be called a classical one. If the deciphering process is a lot harder than the enciphering process, then one can assume that even everybody knows how the messages are encoded, it is still difficult for those without deciphering keys to decode the cipher text. Therefore, such a cryptosystem is called a public key system. How to measure the level of difficulty? It is measured by the amount of time needed to solve the problem. Please see the last section for a brief introduction on that subject. 6.2 RSA Cryptosystem: RSA are from the names of its inventors: Rivest, Shamir, and Adleman. This system is based on the assumption that in Z m, it is relatively easier to compute modulo exponentiation thanks to Fermat and Euler, also see an algorithm in Section 2, but it is generally difficult to factor a large integer. Choosing System Parameters First, Bob chooses two distinct primes p and q. These primes are usually very large in order to add difficulty for breaking the ciphers. Let n = pq and randomly pick a number e between 1 and φn such that e, φn = 1, assume that there is an oracle, or a random number generator, helping Bob. Making Enciphering and Deciphering Keys Then, compute d φn e 1. Now Bob tells Alice the enciphering key K E = n, e please do not view this as a g.c.d!; and, he conceals the deciphering keys K D = n, d. He also assumes that Alice may not be able to keep the secret and the keys K D may be known by other people such as other boyfriends of Alice. The Encoding and Decoding Process Bob then tells Alice that the alphabet of both the cipher text and the plain text will be in Z n, the plain text may be represented by k-graph base N numbers, or k-digit base-n numbers, and the enciphering function is C = fp n P e, as long as Alice is careful enough to pick up P so that P, n = 1. However, the assumption P, n = 1 is not necessary, as we shall see later. When Bob receives such a coded message from Alice, Bob knows how to decode it, since he knows the deciphering function f 1 C n C d. This is because that as ed 1 mod φn, ed = sφn + 1, for some integer 23

s, and so by Euler, and as P, n = 1, P φn 1 mod n. It follows that f 1 C n C d = P e d = P sφn+1 = P φn s P P mod n. But the public must first factor n to find K D. Therefore, the harder the factorization of n is, the safer the code will be. 6.3 Example: Let p = 281, q = 167. Then n = 46927. Pick e = 39423. Thus the enciphering key is 46927, 39423 and the deciphering key is 46927, 26767. In order to use the English Alphabet in the messages, Bob also tells Alice to use base-n representation of the numerics with N = 26. To send a message Y ES to Bob, Alice first finds the numerical equivalent of Y ES = 24418 P = 2426 2 + 426 + 18 = 16346 in base-10. Next, Alice computes C = P m = 16346 39423 46927 21166 in Z n, and then converts C to Base-26 numbers and their letter equivalents: C = 126 3 + 526 2 + 826 + 2 1582 = BF IC. And she transmits BF IC to Bob. Receiving the message BF IC from Alice, Bob converts it back to base-10 numbers BF IC = 21166, then applies the deciphering key to compute 21166 26767 46927 16346. After he converts it to base-26 numbers, he recognizes that the message is Y ES, and is overjoyed. 6.4 The Knapsack Problem: Given a k-tuple {v i } = {v 0, v 1,, v k 1 } of positive integers and an integer V, find a k-bit number n = ɛ k 1 ɛ 1 ɛ 0 2 such that k 1 i=0 ɛ iv i = V, if such an n exists. 6.4A Example: For k = 4, v i = i + 1, 0 i 3, if V = 11, then no such n exists, but if V = 5, then one such solution is n = 1001 2. If V = 6, then both n = 1010 2 and n = 0111 2 are solutions. 6.4B Example: For fixed integer k > 1, let v i = 2 i, for 0 i k 1. Then the corresponding Knapsack Problem has a solution if and only if V 2 k 1 the answer is the binary representation of the base-10 integer V. 6.4C Note that there may or may not be a solution for given {v i } = {v 0, v 1,, v k 1 } and V. When there is a solution, there may be more than one solution. A k-tuple {v i } = {v 0, v 1,, v k 1 } is superincreasing if v 0 v 1 v k 1 and if, for each i = 1, 2, k, v i > v 0 + v 1 + v i 1. 6.4D Example: {2, 3, 7, 15, 31} is superincreasing. The k + 1-tuple in 6.4B is also superincreasing. But the 4-tuple in 6.4A is not. 24

6.5 Superincreasing Knapsack Problem We provide an algorithm that runs in polynomial time and solves the Superincreasing Knapsack Problem. Assume that a superincreasing k-tuple {v 0,, v k 1 } and an integer V are given. INITIALIZATION: Set W := V and j := k. ITERATION 1 FOR i := 1 TO j, DO IF v j i > W, THEN set ɛ i := 0; OTHERWISE ɛ i := 1, W := W v i, j := i IF W > 0, GOTO 1 When the algorithm halts, either W = 0, in which case a solution ɛ k 1 ɛ 0 2 has been found, or W > 0, in which case no solution exists, since all of the remaining v i are > W. 6.5A Exercise: The solution given by 6.5, if exists, is unique. 6.5B Example: Let {v i } = {2, 3, 7, 15, 31} and V = 24. Apply Algorithm 6.5. Then First ɛ 4 = 0 and ɛ 3 = 1. Replace 24 by 24 15 = 9 to get ɛ 2 = 1; replacing 9 by 9 7 = 2 to get ɛ 1 = 0 and ɛ 0 = 1. Thus the answer is n = 01101 2 = 13. 6.6 The Knapsack Cryptosystem is also known as the Merkle-Hellman system. Choosing System Parameters First, choose a superincreasing k-tuple {v 0, v 1,, v k 1 }, an integer m > k 1 i=0 v i, and an integer a with a, m = 1, with the help of an oracle, a random number generator. Making Enciphering and Deciphering Keys Then compute b m a 1 this is why we need a, m = 1 and w i m av i, 0 i k 1. The enciphering keys will then be K E = {w 0,, w k 1 }, and the deciphering key is K D = b, m. The Encoding and Decoding Process Bob makes all the above and he keeps K D a secret. After he has done it, he publicizes the encryption key K E. If Alice wants to send a plain text in a k-bit number form P = ɛ k 1 ɛ 0 2 to Bob, as she knows K E, she can computes C = fp = k 1 i=0 ɛ iw i and transmits C. Receiving the message C from Alice, Bob uses his key K D = b, m to find the least positive residue V of bc in Z m. Bob knows that since bc m ɛi bw i m ɛi v i, it must be the case that V = k 1 i=0 ɛ iv i. Here we need V < m, and i v i < m. Now Bob applies Algorithm 6.5 to find the unique solution ɛ k 1 ɛ 0 2 and recovers P. 25

6.6A Example: Let s use the same 5-tuple {2, 3, 7, 15, 31} again. Let m = 61, a = 17. Then b = 18, K E = 34, 51, 58, 11, 39 and K D = 18, 61. To send a message W HY to Bob, Alice first finds the equivalents: W = 22 = 10110 2 51 + 58 + 39 = 148, H = 7 = 00111 2 34 + 51 + 58 = 143, and Y = 24 = 11000 2 11 + 39 = 50. Then she transmits the sequence 148, 143, 50. Receiving 148, 143 50 from Alice, Bob multiplies the sequence by 18 in Z 61 to get 41, 12, 46, respectively. Then Bob applies Algorithm 6.5 to V = 41 to get 10110 2, to V = 12 to get 00111 2, and to V = 46 to get 11000 2, and so he knows the message. 26

7. The Primarity Test and Factorization 7.1 When an integer is a composite? Let n be an integer. Suppose that there exist integers x, y such that x 2 y 2 mod n but x ±y mod n. Then each of the following holds. i n is a composite. ii Let d = x y, n. Then 1 < d < n. Proof: Use the property that if n is a prime and if n ab, then n a or n b with a = x y and b = x + y to see that n must be a composite. d = n = n x y = x y mod n. Thus assume d = 1. Use the property that if a, b = 1 and if a bc, then a c. From n x 2 y 2 = x yx + y and d = 1, we have n x + y = x y mod n. 7.1A Example: For n = 3837523, we have been told the following 9398 2 5 5 19 mod n 19095 2 2 2 5 11 13 19 mod n 1964 2 3 2 13 3 mod n 17078 2 2 6 3 2 11 mod n Multiply these relations side by side to get 9398 19095 1964 17078 2 2 4 3 2 5 3 11 13 2 19 2 mod n 2230387 2 2586705 2 mod n. Let x = 2230387 and y = 2586705. We verify that x ±y mod n. Then we can factor n by computing x y, n = 2586705 2586705, 3837523 = 1093, and 3837523 = 3511. 1093 Hence n = 3837523 = 10933511. 7.2 Example: As 7 2 2 2 mod 15 and 7 ±2 mod 15, we conclude that 15 is a composite, and 5 = 7 2, 15 is a nontrivial factor of 15. 7.3 When an integer is a composite? We apply Fermat s Little Theorem 2.12, which states that if p > 2 is a prime, then 2 p 1 1 mod p. Suppose that 12 is a prime, then we should have 2 11 1 mod 12. If this is not true, then 12 is a composite. Perform these computation: 2 4 = 16 12 4 12 2 2 2 8 = 2 4 2 12 2 2 2 12 2 2 2 12 = 2 8 2 4 12 2 2 2 2 12 2 2 12 1 27

Thus 12 must be a composite. This example is extended to the next test. 7.4 Miller-Robin Primarity Test. Input: An odd integer n > 1 such that for some integer k 0 and odd integer m, n 1 = 2 k m. Initialization: Choose a random integer a with 1 < a < n 1. Compute b 0 n a m. If b 0 n ±1, then STOP and output the message that n is probably a prime. Otherwise continue. Iteration: FOR i = 1, 2,..., k, DO Set b i n b 2 i 1. IF b i n 1, THEN STOP and output the message that n is a composite, and that b i 1 1, n is a nontrivial factor of n. IF b i n 1, THEN STOP and output the message that n is probably a prime. OTHERWISE continue. Reason: If b i n 1 but b i 1 n ±1, then b i 1 1b i 1 + 1 n b 2 i 1 1 n b i 1 n 0 and so view x = b i 1 and y = 1 to see that if n were a prime, then at Step i 1, either b i 1 n 1 or b i 1 n 1, and so the Algorithm must have stopped. Since the algorithm did not stopped, we must have x n ±y, and so by 7.1, d = x y, n = d i 1 1, n must be a proper factor of n. 7.5 Example: Test if n = 561 is a composite. Then n 1 = 560 = 16 35, and so 2 k = 2 4, k = 4 and m = 35. Pick a = 2. Then b 0 2 35 263 mod 561 b 1 b 2 0 166 mod 561 b 2 b 2 1 67 mod 561 b 3 b 2 2 1 mod 561 Thus 561 is a composite and b 2 1, n = 66, 561 = 33 is a factor of 561. 7.6 If n is a composite and for some a with 1 < a < n 1, a n 1 1 mod n, then n is called a pseudo prime for the base a or a pseudo prime to the base a. If, in addition, that n passes the Miller-Robin test, then n is called a strong pseudo prime for the base a. In other words, pseudo primes are numbers that pretend to be primes. 7.6A Example: n = 561 is a pseudo prime for the base 2, but it is not a strong pseudo 28

prime for the base 2. 7.6B Example: n = 91 is a pseudo prime for the base 3, as 3 90 1 mod 91. But 91 is not a strong pseudo prime for the base 2, because 2 90 64 mod 91. In fact, from 2 90 64 mod 91 we know that 91 is not a prime. 7.6C Exercise: Find all bases b for which 15 is a pseudo prime. 7.7 When an integer is a prime? A straight forward fact is that if n > 1 is a composite, then n must have a nontrivial factor p such that 1 < p n. Therefore, one way to test if n is a prime is to perform the following. Input: Integer n > 0. Initialization: Let [ n] be the largest integer that is not bigger than n. Iteration: For k = 2,...[ n], use division to see if k n. Remark: The amount of computation may be too much. 7.8 Universal Exponent Factorization Method. Input: An integer n > 1 and an integer r > 0 such that for all a with a, n = 1, a r n 1. The number r is referred as the universal exponent. Initialization: Write r = 2 k m with m odd. Iteration: FOR a = 2,, n 2, DO IF a, n > 1, THEN STOP and output a message that a n. OTHERWISE Set b 0 n a m and FOR u = 0, 1,, k 1, DO Set b u+1 n b 2 u IF b 0 n 1 OR IF for some u > 0, b u n 1, THEN move to the next value of a. IF for some u 0, b u+1 n 1 but b u n ±1, THEN STOP and b u 1, n is a nontrivial factor of n. OTHERWISE continue. Remark: The existence of r guarantees that b u+1 n 1 for some u. Why does this work? See the reason for the Miller-Robin Primarity Test. 7.8A An application: Given n, e and d in the RSA, to factor n, we can set r = ed 1 and write r = 2 k m with m odd. Then apply 7.8 to find a proper factor of n. Example: In an RSA system, it is known that n = 221, e = 35 and d = 11. Factor n. Let r = ed 1 = 384 = 2 7 3. Thus m = 3 and k = 7. Pick a = 2 and set b 0 = a m 221 8. 29

Then compute b 1 221 64 b 2 221 118 b 3 221 1 Thus 118 1, 221 = 13 is a proper factor of n = 221. It follows that 221 = 1317. 7.9 Exponent Factorization Method. Input: Integer n > 0, and an integer r > 0 and an integer a such that a r n 1. Initialization: Write r = 2 k m with m odd. Iteration: Set b 0 n a m. FOR u = 0, 1,, k 1, DO Set b u+1 n b m u IF b 0 n 1, OR IF for some u > 0, b u n 1, THEN STOP, and the method does not factor n. IF for some u 0, b u+1 n 1 but b u n ±1, THEN STOP and b u 1, n is a nontrivial factor of n. 7.10 The p 1 Factoring Algorithm. Input: An integer n > 0, an integer a > 1 usually pick a = 2 as a start and a bound B > 0. Initialization: Set b 1 a mod n. Iteration: FOR j = 2,, B, DO Set b j n b j j 1. Note: b B n a B! Compute d = b j, n. IF 1 < d < n, THEN d is a proper factor of n. Reason: Suppose that p is a prime, p n and p 1 has small prime factors. Then when B is larger enough, B! will contain all the prime factors of p 1 and so p 1 B!. Thus we can write B! = p 1k for some integer k. Therefore, by Fermat, b B p a p 1k p 1. Thus p b 1 and p n, and so p b 1, n. 7.10A Example: n = 57. Pick a = 2 and B = 6. The first factor comes out at j = 2. 7.10B Example: n = 133. Pick a = 2 and B = 5. Note that b 2 133 4 but 4 1, 133 = 1; b 3 133 64, and 64 1, 133 = 7. hence 133 = 7 19. 7.10C Example: n = 59. Pick a = 2 and B = 5. Compute b 1 = 133 2 and 2, 59 = 1, b 2 133 4 and 4, 59 = 1, b 3 59 64 133 5 and 5, 59 = 1, b 4 59 5 4 59 125 5 59 35 and 35, 59 = 1, b 5 59 35 5 59 7 2 2 7 5 4 5 59 10 2 7 35 5 59 41 49 25 59 30

18 5 10 5 59 31 10 59 54 and 54, 59 = 1. Therefore, the algorithm does not tell anything. However, the above shows that for p = 2, 3, 5, p 59. One can also check that 7 59. Hence all prime number less than 59 cannot divide 59, and so 59 must be a prime. 7.11 Determining pseudo primes Let n be an odd composite integer. i n is a pseudo prime for the base b, where b, n = 1, if and only if the least positive power m of b for which b m 1 mod n satisfies m n 1. Such a number m is called the order of the element b in the multiplicative group Z n = {x Z n : n, x = 1}. Also recall that m =ord n b. ii If n is a pseudo prime for the base b 1 and b 2, where b 1, n = 1 and b 2, n = 1, then n is a pseudo prime for the base b 1 b 2 and for the base b 1 b 1 2, where b 1 2 is an integer such that b 2 b 1 2 1 mod n. iii If for some base b Z n, b n 1 1 mod n, then for at least half of the members b Z n, b n 1 1 mod n. 7.12 A Carmichael number is a composite n such that for each b Z n, b n 1 1 mod n. 7.13 Example: n = 561 = 3 11 17 is a Carmichael number. Note that 560 is divisible by 3 1, 11 1, 17 1. 7.14 let n be an odd composite integer. i If n is divisible by a perfect square > 1, then n is not a Carmichael number. ii If n is square free, then n is a Carmichael number if and only p 1 n 1 for every prime p dividing n. 7.15 A Carmichael number must have at least three distinct prime factors. 7.16 A generalization of Example 7.1A: Suppose we want to factor n = 3837523, and we have been told the following 9398 2 5 5 19 mod n 19095 2 2 2 5 11 13 19 mod n 1964 2 3 2 13 2 mod n 17078 2 2 6 3 2 11 mod n 8077 2 2 19 mod n 3397 2 2 2 5 13 2 mod n 14262 2 5 2 7 2 13 mod n 31

Represent these relations by a matrix B = b ij whose columns are labelled with the prime factors p 1, p 2, involved on the right side in these relations, and whose rows are labelled with the numbers n 1, n 2, on the left side of these relations, in such a way that the ith row, jth column entry of this matrix is b ij if p a ij j n i but p a ij+1 j n i. For this example, with n 1 = 9398, n 2 = 19095, n 3 = 1964, n 4 = 17078, n 5 = 8077, n 6 = 3397, n 7 = 14262 and p 2 = 2, p 2 = 3, p 3 = 5, p 4 = 7, p 5 = 11, p 6 = 13, p 7 = 17, p 8 = 19 the matrix B is B = 0 0 5 0 0 0 0 1 2 0 1 0 1 1 0 1 0 2 0 0 0 3 0 0 6 2 0 0 1 0 0 0 1 0 0 0 0 0 0 1 5 0 1 0 0 2 0 0 0 0 2 2 0 1 0 0 We look for linear independencies mod 2 among the rows. As there are more columns than rows in this example, there will be such dependencies. Each of such dependency will give rise to a square relation mod n, which provides a possibly way to factor n with smaller numbers to manipulate. We make a few such attempts to factor n, as follows. Trail 1 Rows 1, 5 and 6 are linearly dependent mod 2, and multiply the corresponding relations side by side to get. 9398 8077 3397 2 2 3 5 3 13 19 2 mod n 3590523 2 247000 2 mod n As 3590523 247000 mod n, 7.1 does not tell us anything. Trail 2 Rows 3 and 7 are linearly dependent mod 2, and multiply the corresponding relations side by side to get 1964 14262 2 3 5 7 13 2 2 mod n 1147907 2 17745 2 mod n As 1147907 17745 mod n, we apply 7.1 to conclude that 1147907 17745, n = 1093 is a proper factor of n. Remark: The above method is a special case of a method called the quadratic sieve. 32

Basically, we make use of linearly dependencies over Z 2 in the matrix B to get congruence relations like x 2 = product of small primes, and apply 7.1 or improvement form of 7.1 to this resulting congruence relation convert it to the form x 2 y 2 mod n. How do we get those useful relations? The main point is to produce squares that are slightly bigger than a multiple of n, and so that are small modulo n. Usually, it takes the form of [ an + b] for small values of a and b. Make some trials to find some that are useful in the quadratic sieve. 7.17 Let b > 1. Then for any two positive integers m, n, gcdb m 1, b n 1 = b gcdm,n 1. Proof: We argue by induction on max{m, n}. If m = n or if max{m, n} = 1, the assertion holds trivially. Assume that m n 1 and that the statement holds for smaller values of max{m, n}. Without loss of generality, we assume that m > n. Note that when m > n, b m 1 b m n b n 1 = b m n 1. Thus if an integer d divides two of the three integers b m 1, b n 1 and b m n 1, then d divides the third. It follows that gcdb m 1, b n 1 = gcdb n 1, b m n 1. Since m > n, max{m n, n} < max{m, n}. By induction, gcdb m 1, b n 1 = gcdb n 1, b m n 1 = b gcdm,m n 1. What is left is to show that gcdm, m n = gcdm, n. 7.18 Fix a positive integer b. Let n be a positive integer. If a prime p divides b n 1, then either p b d 1 for some proper factor d > 1 of n, or p 1 mod n. Proof: By Fermat, b p 1 1 mod p, and so p b p 1. Since p b n 1, by 7.17, p b gcdn,p 1 1. Let d = gcdn, p 1. If d < n, then d is a proper factor of n. If d = n, then n p 1 and so p 1 mod n. 7.19 When p is odd and n is odd, we have 2 p 1. Since gcd2, n = 1, if n p 1, we 33