Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 8 Overview. Analysis of Algorithms Algorithms – Time Complexity – Space Complexity An algorithm whose time complexity is bounded by a polynomial.

Similar presentations


Presentation on theme: "Lecture 8 Overview. Analysis of Algorithms Algorithms – Time Complexity – Space Complexity An algorithm whose time complexity is bounded by a polynomial."— Presentation transcript:

1 Lecture 8 Overview

2 Analysis of Algorithms Algorithms – Time Complexity – Space Complexity An algorithm whose time complexity is bounded by a polynomial is called a polynomial-time algorithm. – An algorithm is considered to be efficient if it runs in polynomial time. CS 450/650 Lecture 8: Algorithm Background 2

3 Time and Space Should be calculated as function of problem size (n) – Sorting an array of size n, – Searching a list of size n, – Multiplication of two matrices of size n by n T(n) = function of n (time) S(n) = function of n (space) relative rates of growth – 1000n vs. n 2 3 CS 450/650 Lecture 8: Algorithm Background

4 Definitions  T(n) = O(f(n)): T is bounded above by f The growth rate of T(n) <= growth rate of f(n)  T(n) =  (g(n)): T is bounded below by g The growth rate of T(n) >= growth rate of g(n)  T(n) =  (h(n)): T is bounded both above and below by h The growth rate of T(n) = growth rate of h(n)  T(n) = o(p(n)): T is dominated by p The growth rate of T(n) < growth rate of p(n) 4 CS 450/650 Lecture 8: Algorithm Background

5 Time Complexity  C  O(n)  O(log n)  O(nlogn)  O(n 2 )  …  O(n k )  O(2 n )  O(k n )  O(n n ) 5 CS 450/650 Lecture 8: Algorithm Background Polynomial Exponential O(2 log n )

6 P, NP, NP-hard, NP-complete A problem belongs to the class P if the problem can be solved by a polynomial-time algorithm A problem belongs to the class NP if the correctness of the problem’s solution can be verified by a polynomial- time algorithm A problem is NP-hard if it is as hard as any problem in NP – Existence of a polynomial-time algorithm for an NP-hard problem implies the existence of polynomial solutions for every problem in NP NP-complete problems are the NP-hard problems that are also in NP 6 CS 450/650 Lecture 8: Algorithm Background

7 Relationships between different classes NP P NP-complete NP-hard 7 CS 450/650 Lecture 8: Algorithm Background

8 Lecture 9 Rivest-Shamir-Adelman (RSA) CS 450/650 Fundamentals of Integrated Computer Security Slides are modified from Hesham El-Rewini

9 RSA Invented by Cocks (GCHQ), independently, by Rivest, Shamir and Adleman (MIT) Two keys e and d used for Encryption and Decryption – The keys are interchangeable M = D(d, E(e, M) ) = D(e, E(d, M) ) – Public key encryption Based on problem of factoring large numbers – Not in NP-complete – Best known algorithm is exponential 9 CS 450/650 Lecture 9: RSA

10 RSA To encrypt message M compute – c = M e mod N To decrypt ciphertext c compute – M = c d mod N 10 CS 450/650 Lecture 9: RSA

11 Let p and q be two large prime numbers Let N = pq Choose e relatively prime to (p  1)(q  1) – a prime number larger than p-1 and q-1 Find d such that ed mod (p  1)(q  1) = 1 Key Choice 11 CS 450/650 Lecture 9: RSA

12 RSA Recall that e and N are public If attacker can factor N, he can use e to easily find d – since ed mod (p  1)(q  1) = 1 Factoring the modulus breaks RSA It is not known whether factoring is the only way to break RSA 12 CS 450/650 Lecture 9: RSA

13 Does RSA Really Work? Given c = M e mod N we must show – M = c d mod N = M ed mod N We’ll use Euler’s Theorem – If x is relatively prime to N then x  (N) mod N =1  (n): number of positive integers less than n that are relatively prime to n. If p is prime then,  (p) = p-1 13 CS 450/650 Lecture 9: RSA

14 Does RSA Really Work? Facts: – ed mod (p  1)(q  1) = 1 – ed = k(p  1)(q  1) + 1by definition of mod –  (N) = (p  1)(q  1) – Then ed  1 = k(p  1)(q  1) = k  (N) M ed = M (ed-1)+1 = M  M ed-1 = M  M k  (N) = M  (M  (N) ) k mod N = M  1 k mod N = M mod N 14 CS 450/650 Lecture 9: RSA

15 Example Select primes p=11, q=3. N = p* q = 11*3 = 33 Choose e = 3 check gcd(e, p-1) = gcd(3, 10) = 1 – i.e. 3 and 10 have no common factors except 1 check gcd(e, q-1) = gcd(3, 2) = 1 therefore gcd(e, (p-1)(q-1)) = gcd(3, 20) = 1 15 CS 450/650 Lecture 9: RSA

16 Example (cont.) p-1 * q-1 = 10 * 2 = 20 Compute d such that e * d mod (p-1)*(q-1) = 1 3 * d mod 20 = 1 d = 7 Public key = (N, e) = (33, 3) Private key = (N, d) = (33, 7) 16 CS 450/650 Lecture 9: RSA

17 Example (cont.) Now say we want to encrypt message m = 7 c = M e mod N = 7 3 mod 33 = 343 mod 33 = 13 – Hence the ciphertext c = 13 To check decryption, we compute M' = c d mod N = 13 7 mod 33 = 7 17 CS 450/650 Lecture 9: RSA

18 More Efficient RSA Modular exponentiation example – 5 20 = 95367431640625 = 25 mod 35 A better way: repeated squaring – Note that 20 = 2  10, 10 = 2  5, 5 = 2  2 + 1, 2 = 1  2 – 5 1 = 5 mod 35 – 5 2 = (5 1 ) 2 = 5 2 = 25 mod 35 – 5 5 = (5 2 ) 2  5 1 = 25 2  5 = 3125 = 10 mod 35 – 5 10 = (5 5 ) 2 = 10 2 = 100 = 30 mod 35 – 5 20 = (5 10 ) 2 = 30 2 = 900 = 25 mod 35 No huge numbers and it’s efficient! CS 450/650 Lecture 9: RSA 18

19 RSA key-length strength RSA has challenges for different key-lengths – RSA-140 Factored in 1 month using 200 machines in 1999 – RSA-155 (512-bit) Factored in 3.7 months using 300 machines in 1999 – RSA-160 Factored in 20 days in 2003 – RSA-200 Factored in 18 month in 2005 – RSA-210, RSA-220, RSA-232, … RSA-2048 19 CS 450/650 Lecture 9: RSA

20 Symmetric vs Asymmetric Secret Key (Symmetric)Public Key (Asymmetric) Number of keys12 Protection of keyMust be kept secretOne key must be kept secret; the other can be freely exposed Best usesCryptographic workhorse; secrecy and integrity of datasingle characters to blocks of data, messages, files Key exchange, authentication Key distributionMust be out-of-bandPublic key can be used to distribute other keys SpeedFastSlow; typically, 10,000 times slower than secret key CS 450/650 Fundamentals of Integrated Computer Security 20

21 Group Work Find keys d and e for the RSA cryptosystem with p = 7 and q = 11 Solution – p*q = 77 – (p-1) * (q-1) = 60 – e = 37 – d = 13 – n = 13 * 37 = 481 = 1 mod 60 21 CS 450/650 Lecture 9: RSA


Download ppt "Lecture 8 Overview. Analysis of Algorithms Algorithms – Time Complexity – Space Complexity An algorithm whose time complexity is bounded by a polynomial."

Similar presentations


Ads by Google