Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 The Complexity of Primality Testing

2 What is Primality Testing? Testing whether an integer is prime or not. – An integer p is prime if the only integers that divide p evenly are 1 and p itself. – If an integer is not prime, it is composite. Every composite number can be written in an unique way as a product of primes. – Example: 504 = 23 x 32 x 7 prime factorization. 2 128 = 340282366920938463463374607431768211456

3 Why is Primality Testing Important? Primality Testing these days is used in computer security algorithms. Most notable of these is the RSA Algorithm which relies on the apparent difficulty of factoring a large integer. – RSA Codes (Rivest-Shamir-Adelamn) use 128 bit integers that are product of two primes on 64 bits each. Public-key cryptography – Uses a 128-bit key k and the message data x is encrypted with a function f k (x) = y.

4 Properties of Modular Arithmetic 1.[(a mod n) + (b mod n)] mod n = (a + b) mod n 2.[(a mod n) - (b mod n)] mod n = (a - b) mod n 3.[(a mod n) x (b mod n)] mod n = (a x b) mod n Modular Arithmetic Let p be any integer. The integers modulo p are 0,1,…,p-1. We define +, -, and * on integers modulo p by performing the ordinary operation and keep the remainder of the result divided by p

5 The degree of number a modulo p is the smallest positive power that is equal to 1 If p is a prime, then a p-1 = 1 modulo p. This statement is called Fermat’s theorem. The degree of a modulo p (prime) is always a divisor of p-1. If p is a prime, there is always some a that has degree p-1 modulo p. Degree of a Number

6 Random-Polynomial Primality Testing Monte-Carlo algorithm Theorem: The language of composite numbers is in RP The facts: if p is prime, then x p-1 mod p =1, this is the Fermat's theorem. if p is composite, and there is an x at all for which x p-1 mod p is not 1, then for at least half the values of x in the range 1 to p-1, we shall find x p-1 ≠ 1.

7 Monte - Carlo algorithm for the composite numbers: 1.Pick an x at random in the range 1 to p - 1. 2.Compute x p-1 modulo p. Note that if p is an n- bit number, then this calculation takes O(n 3 ) time 3.If x p-1 ≠ 1 modulo p, accept; x is composite. Otherwise, halt without accepting. * If p is prime, then x p-1 = 1 modulo p, so we always halt without accepting ; Random-Polynomial Primality Testing

8 Recall for class RP: A language is accepted in random polynomial time if there is a polynomial-time, randomized Turing machine that has at lease 50% chance of accepting the inputs that is in the language. If the input is not in the language, then this TM never accepts. Carmichael numbers: x c-1 = 1 mod c, for the majority of x: 1<=x<=c-1 The smallest Carmichael number is 561, Let c= 561 = 3 x 11 x 17 x 560 = 1mod561 Let x=2 2 560 =377396242482154135224155458098826889091692122041644042837 620630024562416239214885208612672517765876754146837503076384489 97705846299247926325614342514326960436

9 Factor in Random Polynomial Time Can We Factor in Random Polynomial Time? The previous algorithm may tell us that a number is composite, but does not tell us how to factor the composite number. It is believed that there is no way to factor numbers, even using randomness, that takes only polynomial time, or even expected polynomial time. If that assumption were incorrect, then the applications that we discussed would be insecure and could not be used.

10 Nondeterministic Primality Tests The language of primes is in NP ∩ co-NP. The language of composite numbers is also in NP ∩ co-NP. They are unlikely to be NP-complete. If either are true, then we will have NP=co-NP, and since primes is in RP and if primes is in NP-complete, RP=NP. Theorem: The set of composite numbers is in NP. PROOF; The nondeterministic, polynomial-time algorithm for the composite numbers is: Step one: Take p as an n-bit number p, Guess a factor f of at most n-bits. f ≠ 1 and f ≠ p. The time taken by any sequence of choices is O(n). Step Two: Divide p by f, Check that the remainder is 0. Accept if so. The time taken is O(n 2 ) on a multi tape TM.

11 Prime is in NP It’s more difficult to recognize primes If p is a prime, then there is a number x between 1 and p-1 that has degree p- 1. For example, for prime p = 7, 3 and 5 both have degree of 6. – To check x has degree p-1, have to check x 2,x 3 …….x p-2 are 1. Which requires p-3 multiplications, and require at least time 2 n. – A better strategy is: the degree of x modulo a prime p is a divisor of p-1. If we knew prime factors of p-1, we can check x p-1)/q /= 1 mod p. If none of these powers of x is equal to 1, then the degree of x must be p-1. The number of tests is O(n). – To factor p-1 into primes, we non deterministically guess the prime factors of p-1 Check that their product is indeed p-1 Check that each is a prime, using the nondeterministic, polynomial-time algorithm that we designed, recursively. – The running time is O(n 5 )

12 Summary of Primality Testing The language of prime and composite numbers are in RP and NP, therefore both are in NP ∩ co-NP. If they either were NP-complete, then we can prove NP=co-NP, If prime testing is NP-complete, if we find a polynomial time algorithm for prime testing, we can prove P=NP. It’s possible that primes are in P if Riemann hypothesis is true. The problem of sieving prime numbers is different than testing primality, and currently can be done in n/ n loglog n.

13


Download ppt "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."

Similar presentations


Ads by Google