WS 2006-07 Algorithmentheorie 03 – Randomized Algorithms (Primality Testing) Prof. Dr. Th. Ottmann.

Slides:



Advertisements
Similar presentations
Cryptography and Network Security
Advertisements

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
MS 101: Algorithms Instructor Neelima Gupta
Agrawal-Kayal-Saxena Presented by: Xiaosi Zhou
Primality Testing Patrick Lee 12 July 2003 (updated on 13 July 2003)
Lecture 8: Primality Testing and Factoring Piotr Faliszewski
Introduction to Modern Cryptography Lecture 6 1. Testing Primitive elements in Z p 2. Primality Testing. 3. Integer Multiplication & Factoring as a One.
Primality Testing By Ho, Ching Hei Cheung, Wai Kwok.
COM 5336 Cryptography Lecture 7a Primality Testing
1 Today’s Material Medians & Order Statistics – Ch. 9.
מבוא מורחב 1 Lecture 4 Material in the textbook on Pages 44-46, of 2nd Edition Sections and Hanoy towers.
Notation Intro. Number Theory Online Cryptography Course Dan Boneh
WS Algorithmentheorie 03 – Randomized Algorithms (Overview and randomised Quicksort) Prof. Dr. Th. Ottmann.
1 Fingerprint 2 Verifying set equality Verifying set equality v String Matching – Rabin-Karp Algorithm.
The RSA Cryptosystem and Factoring Integers (II) Rong-Jaye Chen.
Elementary Number Theory and Methods of Proof. Basic Definitions An integer n is an even number if there exists an integer k such that n = 2k. An integer.
6/20/2015 5:05 AMNumerical Algorithms1 x x1x
Randomized Algorithms Prof. Dr. Th. Ottmann University of Freiburg
WS Algorithmentheorie 03 – Randomized Algorithms (Public Key Cryptosystems) Prof. Dr. Th. Ottmann.
CSE 321 Discrete Structures Winter 2008 Lecture 8 Number Theory: Modular Arithmetic.
Theory I Algorithm Design and Analysis (9 – Randomized algorithms) Prof. Dr. Th. Ottmann.
WS Algorithmentheorie 03 – Randomized Algorithms (Public Key Cryptosystems) 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.
Topic 18: RSA Implementation and Security
CSE 321 Discrete Structures Winter 2008 Lecture 10 Number Theory: Primality.
Software Security Seminar - 1 Chapter 11. Mathematical Background 발표자 : 안병희 Applied Cryptography.

COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)
Stochastic Algorithms Some of the fastest known algorithms for certain tasks rely on chance Stochastic/Randomized Algorithms Two common variations – Monte.
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.
Chapter 14 Randomized algorithms Introduction Las Vegas and Monte Carlo algorithms Randomized Quicksort Randomized selection Testing String Equality Pattern.
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.
Approximation Algorithms Pages ADVANCED TOPICS IN COMPLEXITY THEORY.
Additional Problems.
PRIMES is in P Manindra Agrawal NUS Singapore / IIT Kanpur.
Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 31.
11 -1 Chapter 11 Randomized Algorithms Randomized Algorithms In a randomized algorithm (probabilistic algorithm), we make some random choices.
CPSC 335 Randomized Algorithms Dr. Marina Gavrilova Computer Science University of Calgary Canada.
Analyzing and Testing justified Prime Numbers
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.
6.4 Factoring.
CSE 311: Foundations of Computing Fall 2014 Lecture 12: Primes, GCD.
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.
Umans Complexity Theory Lectures Lecture 7b: Randomization in Communication Complexity.
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.
Primality Testing. Introduction The primality test provides the probability of whether or not a large number is prime. Several theorems including Fermat’s.
CSE 311: Foundations of Computing Fall 2013 Lecture 12: Primes, GCD, modular inverse.
מבוא מורחב 1 Lecture 4 Material in the textbook on Pages 44-46, of 2nd Edition Sections and Hanoy towers.
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 9 Primality Testing Encryption Intro.
RSA Encryption Greg Gronn Laura Trimmer. RSA Encryption  Requires two 30 digit prime numbers to create an encoding/decryption key.  Goal: analyze different.
MA/CSSE 473 Day 08 Randomized Primality Testing Carmichael Numbers
Lecture #5 מבוא מורחב.
Probabilistic Algorithms
Handbook of Applied Cryptography - CH4, from 4.1~4.3
Numerical Algorithms x x-1 Numerical Algorithms
Material in the textbook on pages
Number Theory (Chapter 7)
Lecture 20 Guest lecturer: Neal Gupta
Lecture #5 מבוא מורחב.
Discrete Math for CS CMPSC 360 LECTURE 12 Last time: Stable matching
Material in the textbook on
Mathematical Background for Cryptography
Patrick Lee 12 July 2003 (updated on 13 July 2003)
Cryptography Lecture 16.
Presentation transcript:

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

2WS Randomized algorithms Classes of randomized algorithms Randomized Quicksort Randomized algorithm for Closest Pair Randomized primality test Cryptography

3WS Classes of randomized algorithms Las Vegas algorithms always correct; expected running time (“probably fast”) Example: randomized Quicksort Monte Carlo algorithms (mostly correct): probably correct; guaranteed running time Example: randomized primality test

4WS Primality test Definition: An integer p  2 is prime iff (a | p  a = 1 or a = p). Algorithm: deterministic primality test (naive) Input: integer n  2 Output: answer to the question: Is n prime? if n = 2 then return true if n even then return false for i = 1 to  n/2 do if 2i + 1 divides n then return false return true Complexity:  n)

5WS Primality test Goal: Randomized method Polynomial time complexity (in the length of the input) If answer is “not prime”, then n is not prime If answer is “prime”, then the probability that n is not prime is at most p>0 k iterations: probability that n is not prime is at most p k

6WS Primality test Observation: Each odd prime number p divides 2 p-1 – 1. Examples: p = 17, 2 16 – 1 = = 17 * 3855 p = 23, 2 22 – 1 = = 23 * Simple primality test: 1 Calculate z = 2 n-1 mod n 2 if z = 1 3 then n is possibly prime 4 else n is definitely not prime Advantage: This only takes polynomial time

7WS Simple primality test Definition: n is called pseudoprime to base 2, if n is not prime and 2 n-1 mod n = 1. Example: n = 11 * 31 = mod 341 = 1

8WS Randomized primality test Theorem: (Fermat‘s little theorem) If p prime and 0 < a < p, then a p-1 mod p = 1. Definition: n is pseudoprime to base a, if n not prime and a n-1 mod n = 1. Example: n = 341, a = mod 341 = 56  1

9WS Randomized primality test Algorithm: Randomized primality test 1 1 Randomly choose a  [2, n-1] 2 Calculate a n-1 mod n 3 if a n-1 mod n = 1 4 then n is possibly prime 5 else n is definitely not prime Prob(n is not prim, but a n-1 mod n = 1 ) ?

10WS Carmichael numbers Problem: Carmichael numbers Definition: An integer n is called Carmichael number if a n-1 mod n = 1 for all a with GCD(a, n) = 1. (GCD = greatest common divisor) Example: Smallest Carmichael number: 561 = 3 * 11 * 17

11WS Randomized primality test 2 Theorem: If p prime and 0 < a < p, then the only solutions to the equation a 2 mod p = 1 are a = 1 and a = p – 1. Definition: a is called non-trivial square root of 1 mod n, if a 2 mod n = 1 and a  1, n – 1. Example: n = mod 35 = 1

12WS Fast exponentiation Idea: During the computation of a n-1 (0 < a < n randomly chosen), test whether there is a non-trivial square root mod n. Method for the computation of a n : Case 1: [n is even] a n = a n/2 * a n/2 Case 2: [n is odd] a n = a (n-1)/2 * a (n-1)/2 * a

13WS Fast exponentiation Example: a 62 = (a 31 ) 2 a 31 = (a 15 ) 2 * a a 15 = (a 7 ) 2 * a a 7 = (a 3 ) 2 * a a 3 = (a) 2 * a Complexity: O(log 2 a n log n)

14WS Fast exponentiation boolean isProbablyPrime; power(int a, int p, int n) { /* computes a p mod n and checks during the computation whether there is an x with x 2 mod n = 1 and x  1, n-1 */ if (p == 0) return 1; x = power(a, p/2, n) result = (x * x) % n;

15WS Fast exponentiation /* check whether x 2 mod n = 1 and x  1, n-1 */ if (result == 1 && x != 1 && x != n –1 ) isProbablyPrime = false; if (p % 2 == 1) result = (a * result) % n; return result; } Complexity: O(log 2 n log p)

16WS Randomized primality test 2 primalityTest(int n) { /* carries out the randomized primality test for a randomly selected a */ a = random(2, n-1); isProbablyPrime = true; result = power(a, n-1, n); if (result != 1 || !isProbablyPrime) return false; else return true; }

17WS Randomized primality test 2 Theorem: If n is not prime, there are at most integers 0 < a < n, for which the algorithm primalityTest fails.