Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 31.

Slides:



Advertisements
Similar presentations
Number Theory Algorithms and Cryptography Algorithms Prepared by John Reif, Ph.D. Analysis of Algorithms.
Advertisements

CS 483 – SD SECTION BY DR. DANIYAL ALGHAZZAWI (4) Information Security.
Section 4.1: Primes, Factorization, and the Euclidean Algorithm Practice HW (not to hand in) From Barr Text p. 160 # 6, 7, 8, 11, 12, 13.
MS 101: Algorithms Instructor Neelima Gupta
Primality Testing Patrick Lee 12 July 2003 (updated on 13 July 2003)
22C:19 Discrete Structures Integers and Modular Arithmetic
Number Theory Presented by Shrividya Shivkumar and George Frederick.
Public Key Encryption Algorithm
Week 3 - Friday.  What did we talk about last time?  AES  Public key cryptography.
hap8.html#chap8ex5.
22C:19 Discrete Math Integers and Modular Arithmetic Fall 2010 Sukumar Ghosh.
1 The RSA Algorithm Supplementary Notes Prepared by Raymond Wong Presented by Raymond Wong.
Great Theoretical Ideas in Computer Science.
Foundations of Network and Computer Security J J ohn Black Lecture #10 Sep 18 th 2009 CSCI 6268/TLEN 5550, Fall 2009.
CNS2010handout 8 :: introduction to number theory1 computer and network security matt barrie.
and Factoring Integers (I)
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2009 Tuesday, 28 April Number-Theoretic Algorithms Chapter 31.
RSA ( Rivest, Shamir, Adleman) Public Key Cryptosystem
The RSA Cryptosystem and Factoring Integers (II) Rong-Jaye Chen.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2002 Tuesday, 26 November Number-Theoretic Algorithms Chapter 31.
6/20/2015 5:05 AMNumerical Algorithms1 x x1x
Cryptography Lecture 11: Oct 12. Cryptography AliceBob Cryptography is the study of methods for sending and receiving secret messages. adversary Goal:
and Factoring Integers
Public Encryption: RSA
Cryptography1 CPSC 3730 Cryptography Chapter 9 Public Key Cryptography and RSA.
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.
Mathematics of Cryptography Part I: Modular Arithmetic, Congruence,
Codes, Ciphers, and Cryptography-RSA Encryption
The RSA Algorithm Based on the idea that factorization of integers into their prime factors is hard. ★ n=p . q, where p and q are distinct primes Proposed.
 Introduction  Requirements for RSA  Ingredients for RSA  RSA Algorithm  RSA Example  Problems on RSA.
1 CIS 5371 Cryptography 8. Asymmetric encryption-.
Topic 18: RSA Implementation and Security
Prime Numbers Prime numbers only have divisors of 1 and self
Chapter 9 Mathematics of Cryptography Part III: Primes and Related Congruence Equations Copyright © The McGraw-Hill Companies, Inc. Permission required.

Network and Communications Network Security Department of Computer Science Virginia Commonwealth University.
10.1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 10 Symmetric-Key Cryptography.
RSA Public Key Algorithm. RSA Algorithm history  Invented in 1977 at MIT  Named for Ron Rivest, Adi Shamir, and Len Adleman  Based on 2 keys, 1 public.
RSA and its Mathematics Behind
Great Theoretical Ideas in Computer Science.
RSA Ramki Thurimella.
Extended Euclidean Algorithm Presented by Lidia Abrams Anne Cheng.
Prelude to Public-Key Cryptography Rocky K. C. Chang, February
Cryptography Dec 29. This Lecture In this last lecture for number theory, we will see probably the most important application of number theory in computer.
Cryptography Lecture 7: RSA Primality Testing Piotr Faliszewski.
Modular Arithmetic with Applications to Cryptography Lecture 47 Section 10.4 Wed, Apr 13, 2005.
RSA Prepared by: SITI ZAINAH ADNAN
The RSA Algorithm. Content Review of Encryption RSA An RSA example.
RSA and its Mathematics Behind July Topics  Modular Arithmetic  Greatest Common Divisor  Euler’s Identity  RSA algorithm  Security in RSA.
Lecture 8 Overview. Analysis of Algorithms Algorithms – Time Complexity – Space Complexity An algorithm whose time complexity is bounded by a polynomial.
CSE 311: Foundations of Computing Fall 2014 Lecture 12: Primes, GCD.
22C:19 Discrete Structures Integers and Modular Arithmetic Fall 2014 Sukumar Ghosh.
CS/ECE Advanced Network Security Dr. Attila Altay Yavuz
Scott CH Huang COM 5336 Cryptography Lecture 6 Public Key Cryptography & RSA Scott CH Huang COM 5336 Cryptography Lecture 6.
Public Key Cryptosystems RSA Diffie-Hellman Department of Computer Engineering Sharif University of Technology 3/8/2006.
RSA The algorithm was publicly described in 1977 by Ron Rivest, Adi Shamir, and Leonard Adleman at MIT Partly used for PGP (Pretty Good Privacy) to encrypt.
Chapter 9 Public Key Cryptography and RSA. Private-Key Cryptography traditional private/secret/single key cryptography uses one key shared by both sender.
Lecture 6.1: Misc. Topics: Number Theory CS 250, Discrete Structures, Fall 2011 Nitesh Saxena.
CS Modular Division and RSA1 RSA Public Key Encryption To do RSA we need fast Modular Exponentiation and Primality generation which we have shown.
Ch1 - Algorithms with numbers Basic arithmetic Basic arithmetic Addition Addition Multiplication Multiplication Division Division Modular arithmetic Modular.
9.1 Primes and Related Congruence Equations 23 Sep 2013.
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.
Fuw-Yi Yang1 Textbook: Introduction to Cryptography 2nd ed. By J.A. Buchmann Chap 1 Integers Department of Computer Science and Information Engineering,
Lecture 5 Asymmetric Cryptography. Private-Key Cryptography Traditional private/secret/single key cryptography uses one key Shared by both sender and.
Revision. Cryptography depends on some properties of prime numbers. One of these is that it is rather easy to generate large prime numbers, but much harder.
Chapter Applications of Number Theory Some Useful Results
RSA Cryptosystem Bits PCs Memory MB ,000 4GB 1,020
Number Theory and Euclidean Algorithm
Introduction to Algorithms Second Edition by
Presentation transcript:

Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 31

Theorem 1 If a and b are any integers, not both zero, then gcd(a, b) is the smallest positive element of the set {ax + by : x, y Z}of linear combinations of a and b.

Proof Let s be the smallest positive such linear combination of a and b, and let s = ax + by for some x, y Z. Let q = a/s. Equation implies a mod s = a - qs = a - q(ax + by) = a(1 - qx) + b(-qy), and thus a mod s is a linear combination of a and b as well. But, since a mod s = s. gcd(a, b) | s, since gcd(a, b) divides both a and b and s is a linear combination of a and b. But gcd(a, b) | s and s > 0 imply that gcd(a, b) = s and gcd(a, b)<= s yields gcd(a, b) = s; we conclude that s is the greatest common divisor of a and b.

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

As an example of the running of EUCLID, consider the computation of gcd (30,21): EUCLID(30, 21) = EUCLID(21, 9) = EUCLID(9, 3) = EUCLID(3, 0) = 3.

The extended form of Euclid's algorithm We now rewrite Euclid's algorithm to compute additional useful information. Specifically, we extend the algorithm to compute the integer coefficients x and y such that d = gcd(a,b) = ax + by.

EXTENDED-EUCLID(a, b) 1 if b = 0 2 then return (a, 1, 0) 3 (d',x',y')  EXTENDED-EUCLID(b, a mod b) 4 (d,x,y)  (d',y',x' –floor( a/b) y') 5 return (d,x,y)

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Using the definition of multiplication modulo n, we define the multiplicative group modulo n as. The elements of this group are the set of elements in Z n that are relatively prime to n:

An example of such a group is The size of is denoted (n). This function, known as Euler's phi function, satisfies the equation where p runs over all the primes dividing n (including n itself)

For example, since the prime divisors of 45 are 3 and 5,

Solving modular linear equations We now consider the problem of finding solutions to the equation ax= b (mod n),

Corollary The equation ax =b (mod n) is solvable for the unknown x if and only if gcd(a, n) | b. Corollary The equation ax =b (mod n) either has d distinct solutions modulo n, where d = gcd(a, n), or it has no solutions

MODULAR-LINEAR-EQUATION- SOLVER(a,b,n) 1 (d,x',y')  EXTENDED-EUCLID(a,n) 2 if d | b 3 then x 0  x'(b/d) mod n 4 for i  0 to d – 1 5 do print (x 0 + i(n/d)) mod n 6 else print "no solutions

As an example of the operation of this procedure, consider the equation 14x =30 (mod 100) (here, a = 14, b = 30, and n = 100). Calling EXTENDED-EUCLID in line 1, we obtain (d, x, y) = (2,-7,1). Since 2|30, lines 3-5 are executed. In line 3, we compute x 0 = (-7)(15) mod 100 = 95. The loop on lines 4-5 prints the two solutions: 95 and 45.

The RSA cryptosystem-(1) The RSA system, named after its inventors Ron Rivest, Adi Shamir, and Len Adleman, was the first public-key cryptosystem and is still most important Ron Rivest, Adi Shamir, and Len Adleman Its security is closely related to the difficulty of finding the factorization of a composite integer that is the product of two large primes

The RSA cryptosystem-(2) We explain how Bob generates his private and public RSA keys –n=pq, where p, q are randomly and independently two large prime numbers –Bob also chooses an integer e with 1<e<  (n)=(p-1)(q-1) and gcd(e,  (n))=1 –Bob computes an integer d with 1<d<  (n)=(p- 1)(q-1) and de=1 mod (p-1)(q-1), since gcd(e, (p-1)(q-1))=1, such a number d exists

The RSA cryptosystem-(3) Bob’s public key is the pair (n,e), his private key is d The number n is called the RSA modulus, e is called the encryption exponent, and d is called the decryption exponent

The RSA cryptosystem-(4) Encryption: A plaintext m is encrypted by computing c=m e mod n, 0  m<n The ciphertext is c, if Alice knows the public key (n,e), she can encrypt efficient

The RSA cryptosystem-(5) Decryption: The decryption of RSA is based on the following theorem: (m e ) d mod n =m for any integer m with 0  m<n –Proof: since ed=1 mod (p-1)(q-1), there is an integer l with ed=1+l(p-1)(q-1) –Therefore (m e ) d =m ed =m 1+l(p-1)(q-1) =m(m (p-1)(q-1) ) l –It follows that m ed =m(m (p-1) ) (q-1)l =m mod p –Analogously, we see that (m e ) d =m mod q –Because p and q are distinct prime numbers, we obtain (m e ) d =m mod n –The assertion follows form the fact that 0  m<n

The RSA cryptosystem-(6) Example: –Bob choose p=11 and q=23, then n=pq=253 and (p-1)(q-1)=220, the smallest possible e is 3, then d=147 –We know the plaintext space is {0,1,…,252}, encrypting m=165, we obtain mod 253=110 –Then mod 253=165

The RSA cryptosystem-(7) Security of the secret –We show that computing d from (n,e) is as difficult as finding the prime factors p and q of n –There is no proof that factoring RSA modules is difficult, however, if the factor p and q of the RSA module n are sufficiently large, then nobody yet knows how to factor n

Powers of an element Just as it is natural to consider the multiples of a given element a, modulo n, it is often natural to consider the sequence of powers of a, modulo n, where : a 0,a 1,a 2,a 3,..., modulo n. Indexing from 0, the 0th value in this sequence is a 0 mod n = 1, and the ith value is a i mod n.

Example. For example, the powers of 3 modulo 7 are i i mod

Theorem(Euler) For any integer n > 1,

Theorem(Fermat) If p is prime, then

A number x is a nontrivial square root of 1, modulo n, if it satisfies the equation x 2 =1 (mod n) but x is equivalent to neither of the two "trivial" square roots: 1 or -1, modulo n. For example, 6 is a nontrivial square root of 1, modulo 35. The following corollary will be used in the correctness proof for the Miller-Rabin primality-testing procedure.

Corollary. If there exists a nontrivial square root of 1, modulo n, then n is composite.

Raising to powers with repeated squaring A frequently occurring operation in number-theoretic computations is raising one number to a power modulo another number, also known as modular exponentiation. More precisely, we would like an efficient way to compute a b mod n, where a and b are nonnegative integers and n is a positive integer.

Modular exponentiation is also an essential operation in many primality-testing routines and in the RSA public-key cryptosystem. The method of repeated squaring solves this problem efficiently using the binary representation of b.

Let b k, b k-1,..., b 1,b 0 be the binary representation of b. (That is, the binary representation is k + 1 bits long, b k is the most significant bit, and b 0 is the least significant bit.) The following procedure computes a c mod n as c is increased by doublings and incrementations from 0 to b.

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Pseudoprimality testing We now consider a method for primality testing that "almost works" and in fact is good enough for many practical applications. A refinement of this method that removes the small defect will be presented later. Let denote the nonzero elements of Z n :

If n is prime, then We say that n is a base-a pseudoprime if n is composite and a n - 1 = 1 (mod n).

The following procedure pretends in this manner to be checking the primality of n. It uses the procedure MODULAR- EXPONENTIATION. The input n is assumed to be an integer larger than 2.

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

This procedure can make errors, but only of one type. That is, if it says that n is composite, then it is always correct. If it says that n is prime, however, then it makes an error only if n is a base-2 pseudoprime. How often does this procedure error? Surprisingly rarely. There are only 22 values of n less than 10,000 for which it errors; the first four such values are 341, 561, 645, and 1105.