MA/CSSE 473 Day 08 Randomized Primality Testing Carmichael Numbers

Slides:



Advertisements
Similar presentations
WS Algorithmentheorie 03 – Randomized Algorithms (Primality Testing) Prof. Dr. Th. Ottmann.
Advertisements

Cryptography and Network Security
Chapter 8 – Introduction to Number Theory. Prime Numbers prime numbers only have divisors of 1 and self –they cannot be written as a product of other.
Computability and Complexity
Chapter 8 Introduction To Number Theory. Prime Numbers Prime numbers only have divisors of 1 and Prime numbers only have divisors of 1 and self. self.
Primality Testing Patrick Lee 12 July 2003 (updated on 13 July 2003)
Fermat’s Little Theorem (2/24) Theorem (flt). If p is prime and GCD(a, p) = 1, then a p – 1  1 (mod p). Again, this says that in a mod p congruence, we.
Introduction to Modern Cryptography Lecture 6 1. Testing Primitive elements in Z p 2. Primality Testing. 3. Integer Multiplication & Factoring as a One.
COM 5336 Cryptography Lecture 7a Primality Testing
מבוא מורחב 1 Lecture 4 Material in the textbook on Pages 44-46, of 2nd Edition Sections and Hanoy towers.
Great Theoretical Ideas in Computer Science.
Announcements: 1. Pass in Homework 5 now. 2. Term project groups and topics due by Friday 1.Can use discussion forum to find teammates 3. HW6 posted, due.
1 Fingerprint 2 Verifying set equality Verifying set equality v String Matching – Rabin-Karp Algorithm.
Chapter 8 – Introduction to Number Theory Prime Numbers  prime numbers only have divisors of 1 and self they cannot be written as a product of other numbers.
Theory I Algorithm Design and Analysis (9 – Randomized algorithms) Prof. Dr. Th. Ottmann.
Chapter 8 – Introduction to Number Theory Prime Numbers
Cryptography and Network Security Chapter 8. Chapter 8 – Introduction to Number Theory The Devil said to Daniel Webster: "Set me a task I can't carry.
Chapter 8 – Introduction to Number Theory Prime Numbers  prime numbers only have divisors of 1 and self they cannot be written as a product of other numbers.
CSE 321 Discrete Structures Winter 2008 Lecture 10 Number Theory: Primality.

RSA Parameter Generation Bob needs to: - find 2 large primes p,q - find e s.t. gcd(e, Á (pq))=1 Good news: - primes are fairly common: there are about.
Prabhas Chongstitvatana 1 Primality Testing Is a given odd integer prime or composite ? No known algorithm can solve this problem with certainty in a reasonable.
CPSC 490 Number Theory Primes, Factoring and Euler Phi-function Mar.31 st, 2006 Sam Chan.
MA/CSSE 473 Day 08 Randomized Primality Testing Carmichael Numbers Miller-Rabin test.
The Complexity of Primality Testing. What is Primality Testing? Testing whether an integer is prime or not. – An integer p is prime if the only integers.
MA/CSSE 473 Day 11 Primality testing summary Data Encryption RSA.
PRIMES is in P Manindra Agrawal NUS Singapore / IIT Kanpur.
CS 312: Algorithm Analysis Lecture #4: Primality Testing, GCD This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.Creative.
ENCRYPTION TAKE 2: PRACTICAL DETAILS David Kauchak CS52 – Spring 2015.
9/22/15UB Fall 2015 CSE565: S. Upadhyaya Lec 7.1 CSE565: Computer Security Lecture 7 Number Theory Concepts Shambhu Upadhyaya Computer Science & Eng. University.
6.3 Primality Testing. p2. (1) Prime numbers 1. How to generate large prime numbers? (1) Generate as candidate a random odd number n of appropriate size.
מבוא מורחב 1 Lecture 4 Material in the textbook on Pages 44-46, of 2nd Edition Sections and Hanoy towers.
Chapter 1 Algorithms with Numbers. Bases and Logs How many digits does it take to represent the number N >= 0 in base 2? With k digits the largest number.
MA/CSSE 473 Day 10 Primality Testing. MA/CSSE 473 Day 10 In-class exam: Friday, Sept 28 –You may bring a two-sided 8.5x11 inch piece of paper containing.
MA/CSSE 473 Day 09 Modular Division Revisited Fermat's Little Theorem Primality Testing.
MA/CSSE 473 Day 07 Extended Euclid's Algorithm Modular Division Fermat's little theorem intro.
MA/CSSE 473 Day 9 Primality Testing Encryption Intro.
A Prime Example CS Lecture 20 A positive integer p  2 is prime if the only positive integers that divide p are 1 and p itself. Positive integers.
MA/CSSE 473 Day 9 Primality Testing Encryption Intro.
MA/CSSE 473 Day 07 Extended Euclid's Algorithm Modular Division
Lecture #5 מבוא מורחב.
Encryption Take 2: Practical details
Public Key Encryption Major topics The RSA scheme was devised in 1978
Mathematics of Cryptography
High order procedures Primality testing The RSA cryptosystem
CSE565: Computer Security Lecture 7 Number Theory Concepts
Probabilistic Algorithms
CLOSE Please YOUR LAPTOPS, and get out your note-taking materials.
Handbook of Applied Cryptography - CH4, from 4.1~4.3
Numerical Algorithms x x-1 Numerical Algorithms
DTTF/NB479: Dszquphsbqiz Day 22
Randomness and Computation: Some Prime Examples
Textbook: Introduction to Cryptography 2nd ed. By J.A. Buchmann
Number Theory and Techniques of Proof
Number-Theoretic Algorithms (UNIT-4)
Cryptography and Network Security
MA/CSSE 473 Day 08 Randomized Primality Testing Carmichael Numbers
Introduction to Number Theory
Material in the textbook on pages
Number Theory (Chapter 7)
Cryptography and Network Security
RSA Cryptosystem Bits PCs Memory MB ,000 4GB 1,020
What are some of the ways you that that we can categorise numbers?
Lecture #5 מבוא מורחב.
Introduction to Cryptography
Material in the textbook on
Advanced Analysis of Algorithms
Mathematical Background for Cryptography
Patrick Lee 12 July 2003 (updated on 13 July 2003)
Clements MAΘ October 30th, 2014
Presentation transcript:

MA/CSSE 473 Day 08 Randomized Primality Testing Carmichael Numbers Miller-Rabin test Slide 12 was hidden in 201110. Hide again?

MA/CSSE 473 Day 08 Student questions Primality Testing Implications of Fermat’s Little Theorem What we can show and what we can’t Frequency of “non-Fermat” numbers Carmichael numbers Randomized Primality Testing. 25/37 students had scores above 48. Quote from Dave Rader from last year's "course assessment report": The current book is too low-level, I believe. My concern: The upside: 60% of the students have an A or B+ at this point. The downside: 15% have a grade below "C". When I ask for questions in class, no one has technical questions. Visits to my office to ask about HW problems are very rare. Rather than asking, many of you submit garbage. I give hard problems (not many yet, but many more to come). I don't expect that everyone will get them on your own. Most of you should be able to get most of them; sometimes with some help. Why a certain math prof who sometimes teaches this course does not like the Levitin textbook…

Recap: Fermat's Little Theorem Formulation 1: If p is prime, then for every number a with 1 ≤ a <p, ap-1  1 (mod p) Formulation 2: If p is prime, then for every number a with 1 ≤ a <p, ap  a (mod p) Why is it called "little theorem" Because of his "last theorem", written in 1637, margin of book. Not proven until 1995. Q4-5

"composite" means "not prime" Easy Primality Test? Is N prime? Pick some a with 1 < a < N Is aN-1  1 (mod N)? If so, N is prime; if not, N is composite … Nice try, but… Fermat's Little Theorem is not an "if and only if" condition. It doesn't say what happens when N is not prime. N may not be prime, but we might just happen to pick an a for which aN-1 1 (mod N) Example: 341 is not prime (it is 11∙31), but 2340  1 (mod 341) Definition: We say that a number a passes the Fermat test if aN-1  1 (mod N). If a passes the Fermat test but N is composite, then a is called a Fermat liar, and N is a Fermat pseudoprime. We can hope that if N is composite, then many values of a will fail the Fermat test It turns out that this hope is well-founded If any integer that is relatively prime to N fails the test, then at least half of the numbers a such that 1 ≤ a < N also fail it. "composite" means "not prime" Start with: “Pay very close attention to the material on this slide. If you get it now, you will avoid one of the major points of confusion that students in the course have had in the past.

How many “Fermat liars"? If N is composite, and we randomly pick an a such that 1 ≤ a < N, and gcd(a, N) = 1, how likely is it that aN-1 is  1 (mod n)? If aN-1  1 (mod n) for some a that is relatively prime to N, then this must also be true for at least half of the choices of a < N. Let b be some number (if any exist) that passes the Fermat test, i.e. bN-1  1 (mod N). Then the number a∙b fails the test: (ab)N-1  aN-1bN-1  aN-1, which is not congruent to 1 mod N. Diagram on whiteboard. For a fixed a, f: bab is a one-to-one function on the set of b's that pass the Fermat test, so there are at least as many numbers that fail the Fermat test as pass it. The diagram (next slide, hidden) is from Dasgupta, page 26. Last bullet if ab = ac, we can just divide by a, since gcd(a, N) = 1

Hidden in 201110. Hide again?

Carmichael Numbers A Carmichael number is a composite number N such that ∀ a ∈ {1, ..N-1} (if gcd(a, N)=1 then aN-1 ≡ 1 (mod N) ) i.e. every possible a passes the Fermat test. The smallest Carmichael number is 561 We'll see later how to deal with those How rare are they? Let C(X) = number of Carmichael numbers that are less than X. For now, we pretend that we live in a Carmichael-free world

Where are we now? For a moment, we pretend that Carmichael numbers do not exist. If N is prime, aN-1  1 (mod N) for all 0 < a < N If N is not prime, then aN-1  1 (mod N) for at most half of the values of a<N. Pr(aN-1  1 (mod N) if N is prime) = 1 Pr(aN-1  1 (mod N) if N is composite) ≤ ½ How to reduce the likelihood of error? Do the test for k randomly-generated values of a < N. Probability of error is < (1/2)^k If k=100, dasGupta says the probability of error is less than the probability of a cosmic ray flipping some bits and messing up your computer's computation

The algorithm (modified) To test N for primality Pick positive integers a1, a2, … , ak < N at random For each ai, check for aiN-1  1 (mod N) Use the Miller-Rabin approach, (next slides) so that Carmichael numbers are unlikely to thwart us. If aiN-1 is not congruent to 1 (mod N), or Miller-Rabin test produces a non-trivial square root of 1 (mod N) return false return true Note that this algorithm may produce a “false prime”, but the probability is very low. Does this work? Note that this algorithm may produce a “false prime”, but the probability is very low if k is large enough.

Miller-Rabin test A Carmichael number N is a composite number that passes the Fermat test for all a with 1 ≤ a<N and gcd(a, N)=1. A way around the problem (Rabin and Miller): Note that for some t and u (u is odd), N-1 = 2tu. As before, compute aN-1(mod N), but do it this way: Calculate au (mod N), then repeatedly square, to get the sequence au (mod N), a2u (mod N), …, a2tu (mod N)  aN-1 (mod N) Suppose that at some point, a2iu  1 (mod N), but a2i-1u is not congruent to 1 or to N-1 (mod N) then we have found a nontrivial square root of 1 (mod N). We will show that if 1 has a nontrivial square root (mod N), then N cannot be prime. u is odd? Or should I say "u are odd". To most of the world outside Rose-Hulman, if you would take this course or any 400-level CSSE course, U must be odd! Note that this factorization of N-1 can be fast. Just count how many bits at the end of N-1 are 0 to get t, and then bit-shift N-1 to get u. ON BOARD: Note that aN-1 = au(2^t) =(…( (au)2)2… )2 square t times

Example (first Carmichael number) N = 561. We might randomly select a = 101. Then 560 = 24∙35, so u=35, t=4 au  10135  560 (mod 561) which is -1 (mod 561) (we can stop here) a2u  10170  1 (mod 561) … a16u  101560  1 (mod 561) So 101 is not a witness that 561 is composite (we say that 101 is a Miller-Rabin liar for 561, if indeed 561 is composite) Try a = 83 au  8335  230 (mod 561) a2u  8370  166 (mod 561) a4u  83140  67 (mod 561) a8u  83280  1 (mod 561) So 83 is a witness that 561 is composite, because 67 is a non-trivial square root of 1 (mod 561). Work through another example with the students. N = 105. Suppose we first try a = 8. (Use the modexp interactive program). Enter 8, 104, 105: Get 1. So it passes the Fermat test. What is u? (13). Do 8^13 (8), 8^26(64), 8^52 (1) Then 29^104 = 1. 29^13 = 29, 29^26 = 1