CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

Post on 14-Dec-2015

232 views 2 download

Tags:

transcript

CSE 20: Discrete Mathematics for Computer Science

Prof. Shachar Lovett

2

Today’s Topics:1. Prime factorization2. Primality testing

3

1. Prime factorizationsPrimes are the atoms of integers

4

Primes Natural numbers: positive integers N={1,2,3,…}

Definition: is prime if the only natural numbers that divide it are 1,n

By definition, 1 is not prime.

5

Primes Which of the following is prime?

A. 1B. 6C. 7D. 21

6

Prime factorization Basic theorem of number theory: any

integer can be factored as a product of primes (we will prove this soon)

Moreover, this factorization is unique

Example: 36=2*2*3*3

7

Existence of prime factorization Theorem: For any integer there exist

primes such that

Proof: strong induction Try and prove it by yourself first.

8

Existence of prime factorization Theorem: For any integer there exist primes such that

Proof: strong induction Base case: n=2. 2 is prime. We are done.

Inductive case: let . There are two cases: Case I: n is prime. We are done.

Case II: n is not prime. So there is some such that a|n. So where 1<a,b<n. By strong induction, both a,b have a prime factorization: a= for some primes b= for some primes

So n= is a prime factorization of n.

9

How to find the prime factorization? What is the prime factorization of 100?

A. 2*5B. 2*2*5C. 10*10D. 2*2*5*5E. Other

10

How to find the prime factorization? What is the prime factorization of

82768328638217?

11

How to find the prime factorization? What is the prime factorization of 82768328638217?

Not so easy anymore…

The security of RSA (which for example, protects your bank accounts) is based on the assumption that it is hard to factor numbers

We cannot prove it.

In fact, maybe somebody knows how to factor numbers fast (lets wait for more Snowden revelations…)

12

2. Primality testing

13

Primality testing If it’s hard to factor numbers into

primes, lets focus on an easier problem

Test if a given integer is prime

How can you do it? Try and come up with the best algorithm you can

14

Primality testing Algorithm 1:

isPrime(n):1. For i=2..n-1

1.1 If n MOD i=0: return False

2. Return True

15

Primality testing Algorithm 1:

isPrime(n):1. For i=2..n-1

1.1 If n MOD i=0: return False

2. Return True

How many steps?

A. ~nB. ~n2

C. ~log(n)D. Doesn’t depend on nE. Other

16

Better primality testing? The primality testing algorithm uses n calls to the MOD

function

Even if we assume that MOD can be computed very efficiently (and it can), there are many call

Observation: if n is not prime, then it has a factor of size

Proof: If then .

We can use it to design a faster algorithm.

17

Primality testing Algorithm 1:

isPrime(n):1. For i=2..n-1

1.1 If n MOD i=0: return False

2. Return True

18

Primality testing (II) Algorithm 2:

isPrime(n):1. For i=2..

1.1 If n MOD i=0: return False

2. Return True

19

Primality testing (II) Algorithm 2:

isPrime(n):1. For i=2..

1.1 If n MOD i=0: return False

2. Return True

How many steps?

A. ~nB. ~n2

C. ~log(n)D. Doesn’t depend on nE. Other

20

An even faster algorithm? The prime numbers used in RSA are

very big, with 100s of digits

These algorithms will take forever

There are much faster algorithms, which run in time ~log(n); they are randomized algorithm (e.g. Miller-Rabin)

21

Log vs poly time Assume n=10100

Then n or are very big (>>atoms in universe)

But log(n)<1000 !

Algorithms running in log-time are very efficient!!!