modular arithmetic and the rsa cryptosystem great theoretical ideas in computer science john...

97
Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John Lafferty CS 15-251 Fall 2005 Lecture 9 Sept 27, 2005 Carnegie Mellon University p-1 ´ p 1

Upload: avice-townsend

Post on 19-Jan-2016

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Modular Arithmetic and the RSA Cryptosystem

Great Theoretical Ideas In Computer Science

John Lafferty CS 15-251 Fall 2005

Lecture 9 Sept 27, 2005 Carnegie Mellon University

p-1

´p 1

Page 2: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

MAX(a,b) + MIN(a,b) = a+b

Page 3: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

n|m means that m is an integer multiple of n.

We say that “n divides m”.

True: 5|25 2|-66 7|35,False: 4|5 8|2

Page 4: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Greatest Common Divisor:

GCD(x,y) = greatest k¸1 s.t. k|x and k|y.

Page 5: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

GCD: Greatest Common Divisor

What is the GCD of 12 and 18?

Page 6: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Least Common Multiple:

LCM(x,y) = smallest k¸1 s.t. x|k and y|k.

Prop: GCD(x,y) = xy/LCM(x,y)LCM(x,y) = xy/GCD(x,y)

Page 7: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

GCD(x,y) = xy/LCM(x,y)LCM(x,y) = xy/GCD(x,y)

x = 22*3 = 12; y= 32*5 = 45

GCD(12,45) = 3LCM(12,45) = 22*32*5 =180

x*y = 540

Page 8: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

GCD(x,y) * LCM(x,y) = xy

MAX(a,b) + MIN(a,b) = a+b

Page 9: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

(a mod n) means the remainder when a is

divided by n.

If dn + r = a, 0 <= r < nThen r = (a mod n)and d = (a div n)

Page 10: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Modular equivalence of integers a and b:

a ´ b [mod n]a ´n b

“a and b are equivalent modulo n”

iff (a mod n) = (b mod n)iff n|(a-b)

Page 11: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

31 equals 81 modulo 2

31 ´ 81 [mod 2]

31 ´2 81

(31 mod 2) = 1 = (81 mod 2)

2|(31- 81)

Page 12: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

´n is an equivalence relation

In other words,

Reflexive: a ´n a

Symmetric: (a ´n b) ) (b ´n a)

Transitive: (a ´n b and b ´n c) ) (a ´n c)

Page 13: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

a ´n b $ n|(a-b)“a and b are equivalent

modulo n”

´n induces a natural partition of the integers into n classes:

a and b are said to be in the same “residue class” or “congruence class”

exactly when a ´n b.

Page 14: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

a ´n b $ n|(a-b)“a and b are equivalent

modulo n”

Define the residue class [i] to be the set of all integers that are congruent to i modulo n.

Page 15: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Residue Classes Mod 3:

[0] = { …, -6, -3, 0, 3, 6, ..}[1] = { …, -5, -2, 1, 4, 7, ..}[2] = { …, -4, -1, 2, 5, 8, ..}

[-6] = { …, -6, -3, 0, 3, 6, ..}[7] = { …, -5, -2, 1, 4, 7, ..}[-1] = { …, -4, -1, 2, 5, 8, ..}

Page 16: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Equivalence mod n implies equivalence mod any divisor of

n.

If (x ´n y) and (k|n)Then: x ´k y

Example: 10 ´6 16 ) 10 ´3 16

Page 17: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

If (x ´n y) and (k|n)Then: x ´k y

Page 18: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Fundamental lemma of plus, minus, and times modulo n:

If (x ´n y) and (a ´n b)Then: 1) x+a ´n y+b

2) x-a ´n y-b 3) xa ´n yb

Page 19: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Proof of 3: xa = yb (mod n)

Page 20: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Fundamental lemma of plus minus, and times modulo n:

When doing plus, minus, and times modulo n, I can at any

time in the calculation replace a number with a number in the same residue class modulo n

Page 21: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Please calculate:

249 * 504 mod 251

-2 * 2 = -4 = 247

Page 22: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

A Unique Representation System Modulo n:

We pick exactly one representative from each

residue class. We do all our calculations using these

representatives.

Page 23: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Unique representation system modulo 3

Finite set S = {0, 1, 2}

+ and * defined on S:

+ 0 1 2

0 0 1 2

1 1 2 0

2 2 0 1

* 0 1 2

0 0 0 0

1 0 1 2

2 0 2 1

Page 24: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Unique representation system modulo 3

Finite set S = {0, 1, -1}

+ and * defined on S:

+ 0 1 -1

0 0 1 -1

1 1 -1

0

-1

-1

0 1

* 0 1 -1

0 0 0 0

1 0 1 -1

-1

0 -1

1

Page 25: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

The reduced system modulo

n:

Zn = {0, 1, 2, …, n-1}

Define +n and *n:a +n b = (a+b mod n)

a *n b = (a*b mod n)

Page 26: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Zn = {0, 1, 2, …, n-1}

a +n b = (a+b mod n) a *n b = (a*b mod n)

+n and *n are associative binary operators from Zn X Zn ! Zn:

When ~ = +n or *n :

[Closed] x,y2 Zn ) x ~ y 2 Zn

[Associative] x,y,z2 Zn ) ( x ~ y ) ~ z = x ~ ( y ~ z )

Page 27: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Zn = {0, 1, 2, …, n-1}

a +n b = (a+b mod n) a *n b = (a*b mod n)

+n and *n are commutative, associative binary operators from Zn

X Zn ! Zn:

[Commutative]x,y2 Zn ) x ~ y = y ~ x

Page 28: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

The reduced system modulo 3

Z3 = {0, 1, 2}

Two binary, associative operators on Z3:+3

0 1 2

0 0 1 2

1 1 2 0

2 2 0 1

*3 0 1 2

0 0 0 0

1 0 1 2

2 0 2 1

Page 29: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

The Boolean interpretation ofZ2 = {0, 1}

0 means FALSE 1 means TRUE

+2

XOR

0 1

0 0 1

1 1 0

*2

AND

0 1

0 0 0

1 0 1

Page 30: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

The reduced systemZ4 = {0, 1,2,3}

+ 0 1 2 3

0 0 1 2 3

1 1 2 3 0

2 2 3 0 1

3 3 0 1 2

* 0 1 2 3

0 0 0 0 0

1 0 1 2 3

2 0 2 0 2

3 0 3 2 1

Page 31: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

The reduced systemZ5 = {0, 1,2,3,4}

+ 0 1 2 3 4

0 0 1 2 3 4

1 1 2 3 4 0

2 2 3 4 0 1

3 3 4 0 1 2

4 4 0 1 2 3

* 0 1 2 3 4

0 0 0 0 0 0

1 0

2 0

3 0

4 0

Page 32: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

The reduced systemZ6 = {0, 1,2,3,4,5}

+ 0 1 2 3 4 5

0 0 1 2 3 4 5

1 1 2 3 4 5 0

2 2 3 4 5 0 1

3 3 4 5 0 1 2

4 4 5 0 1 2 3

5 5 0 1 2 3 4

* 0 1 2 3 4 5

0 0 0 0 0 0 0

1 0

2 0

3 0

4 0

5 0

Page 33: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

The reduced systemZ6 = {0, 1,2,3,4,5}

+ 0 1 2 3 4 5

0 0 1 2 3 4 5

1 1 2 3 4 5 0

2 2 3 4 5 0 1

3 3 4 5 0 1 2

4 4 5 0 1 2 3

5 5 0 1 2 3 4

An operator has the

permutation property if

each row and each column

has a permutation of the elements.

Page 34: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

For every n, +n on Zn has the permutation property

+ 0 1 2 3 4 5

0 0 1 2 3 4 5

1 1 2 3 4 5 0

2 2 3 4 5 0 1

3 3 4 5 0 1 2

4 4 5 0 1 2 3

5 5 0 1 2 3 4

An operator has the

permutation property if

each row and each column

has a permutation of the elements.

Page 35: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly 8 distinct multiples of 3 modulo 8.

7

5 3

1

0

6 2

4

Page 36: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly 8 distinct multiples of 3 modulo 8.

7

5 3

1

0

6 2

4

Page 37: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly 8 distinct multiples of 3 modulo 8.

7

5 3

1

0

6 2

4

Page 38: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly 8 distinct multiples of 3 modulo 8.

7

5 3

1

0

6 2

4

Page 39: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly 8 distinct multiples of 3 modulo 8..

7

5 3

1

0

6 2

4

Page 40: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly 8 distinct multiples of 3 modulo 8.

7

5 3

1

0

6 2

4

Page 41: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly 8 distinct multiples of 3 modulo 8.

7

5 3

1

0

6 2

4

Page 42: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly 8 distinct multiples of 3 modulo 8.

7

5 3

1

0

6 2

4

Page 43: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly 8 distinct multiples of 3 modulo 8.

7

5 3

1

0

6 2

4

Page 44: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly 2 distinct multiples of 4 modulo 8.

7

5 3

1

0

6 2

4

Page 45: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly 2 distinct multiples of 4 modulo 8

7

5 3

1

0

6 2

4

Page 46: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There is exactly 1 distinct multiple of 8 modulo 8

7

5 3

1

0

6 2

4

Page 47: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly 4 distinct multiples of 6 modulo 8

7

5 3

1

0

6 2

4

Page 48: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly 4 distinct multiples of 6 modulo 8

7

5 3

1

0

6 2

4

Page 49: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly 4 distinct multiples of 6 modulo 8

7

5 3

1

0

6 2

4

Page 50: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly 4 distinct multiples of 6 modulo 8

7

5 3

1

0

6 2

4

Page 51: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly 4 distinct multiples of 6 modulo 8

7

5 3

1

0

6 2

4

Page 52: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly ? distinct multiples of ? modulo ?

Can you see the general rule?

Page 53: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly LCM(n,c)/c distinct

multiples of c modulo n

Page 54: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

There are exactly LCM(n,c)/c distinct

multiples of c modulo n

There are exactly n/(nc/LCM(n,c)) distinct multiples of c modulo n

There are exactly n/GCD(c,n) distinct

multiples of c modulo n

Page 55: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

The multiples of c modulo n is the set:{0, c, c +n c, c +n c +n c, ….}={kc mod n | 0 <= k <= n-1}

7

5 3

1

0

6 2

4

Multiples of 6

Page 56: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Theorem: There are exactly k= n/GCD(c,n) = LCM(c,n)/c

distinct multiples of c modulo n: { c*i mod n | 0 <= i < k }

Clearly, c/GCD(c,n) ¸ 1 is a whole number

ck = n [c/GCD(c,n)] ´n 0There are <= k distinct multiples of c

mod n: c*0, c*1, c*2, …, c*(k-1)

k is all the factors of n missing from c

cx ´n cy $ n|c(x-y) ) k|(x-y) ) x-y¸ kThere are ¸ k multiples of c

Page 57: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Is there a fundamental lemma of division modulo n?

cx ´n cy ) x ´n y ?

Page 58: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Is there a fundamental lemma of division modulo n?

cx ´n cy ) x ´n y ? NO!

If c=0 [mod n], cx ´n cy for any x and y. Canceling the c is like

dividing by zero.

Page 59: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Repaired fundamental lemma of division modulo n?

c 0 (mod n), cx ´n cy ) x ´n y ?

6*3 ´10 6*8, but not 3 ´10 8.2*2 ´6 2*5, but not 2 ´6 5.

Page 60: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

When can I divide by c?

Theorem: There are exactly n/GCD(c.n) distinct multiples of c modulo n.

Corollary: If GCD(c,n) > 1, then the number of multiples of c is less than n.

Corollary: If GCD(c,n)>1 then you can’t always divide by c.

Proof: There must exist distinct x,y<n such that c*x=c*y (but xy)

Page 61: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Fundamental lemma of division modulo n.

GCD(c,n)=1, ca ´n cb ) a ´n b

Page 62: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Corollary for general c:

cx ´n cy ) x ´n/GCD(c,n) y

Page 63: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Fundamental lemma of division modulo n.

GCD(c,n)=1, ca ´n cb ) a ´n b

Zn* = {x 2 Zn | GCD(x,n) =1}

Multiplication over Zn* will have the

cancellation property.

Page 64: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Z6 = {0, 1,2,3,4,5}Z6

* = {1,5}

+ 0 1 2 3 4 5

0 0 1 2 3 4 5

1 1 2 3 4 5 0

2 2 3 4 5 0 1

3 3 4 5 0 1 2

4 4 5 0 1 2 3

5 5 0 1 2 3 4

* 0 1 2 3 4 5

0 0 0 0 0 0 0

1 0 1 2 3 4 5

2 0 2 4 0 2 4

3 0 3 0 3 0 3

4 0 4 2 0 4 2

5 0 5 4 3 2 1

Page 65: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Suppose GCD(x,n) =1 and GCD(y,n) =1

Let z = xy and z’ = (xy mod n)

It is clear that GCD(z,n) =1. A moment’s thought convinces us

that GCD(z’,n)=1

Page 66: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Zn* = {x 2 Zn | GCD(x,n) =1}

*n is an associative, binary operator. In particular, Zn

* is closed under *n :

x,y 2 Zn* ) x *n y 2 Zn

* .

Proof: Let z = xy. Let z’ = z mod n. z = z’ + kn. Suppose there exists a prime p>1 p|z’ and p|n. z is the sum of two multiples of p, so p|z.

p|z ) that p|x or p|y. Contradiction of x,y 2 Zn*

Page 67: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Z12* = {1,5,7,11}

*12 1 5 7 11

1 1 5 7 11

5 5 1 11 7

7 7 11 1 5

11 11 7 5 1

Page 68: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Z15*

* 1 2 4 7 811

13

14

1 1 2 4 7 811

13

14

2 2 4 814

1 711

13

4 4 8 113

214

711

7 714

13

4 11 2 1 8

8 8 1 211

413

14

7

11

11

714

2 13 1 8 4

13

13

11

7 1 14 8 4 2

14

14

13

11

8 7 4 2 1

Page 69: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Z5* = {1,2,3,4}

*5 1 2 3 4

1 1 2 3 4

2 2 4 1 3

3 3 1 4 2

4 4 3 2 1

Page 70: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

The column permutation property is equivalent to the right cancellation

property:

[b * a = c * a] ) b=c

* 1 2 a 4

b 1 2 3 4

2 2 4 1 3

c 3 1 4 2

4 4 3 2 1

Page 71: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

The row permutation property is equivalent to the left cancellation

property:

[a * b = a *c] ) b=c

* b 2 c 4

1 1 2 3 4

2 2 4 1 3

a 3 1 4 2

4 4 3 2 1

Page 72: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Euler Phi Function

(n) = size of Zn*

= number of 1<=k<n that are relatively prime to n.

p prime ) Zp*= {1,2,3,…,p-1}

) (p) = p-1

Page 73: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Z12* = {1,5,7,11}12) = 4

*12 1 5 7 11

1 1 5 7 11

5 5 1 11 7

7 7 11 1 5

11 11 7 5 1

Page 74: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

(pq) = (p-1)(q-1) if p,q distinct primes

pq = # of numbers from 1 to pqp = # of multiples of q up to pqq = # of multiples of p up to pq1 = # of multiple of both p and q up to pq

(pq) = pq – p – q + 1 = (p-1)(q-1)

Page 75: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Let’s consider how we do arithmetic in Zn and in Zn

*

Page 76: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

The additive inverse of a2 Zn is the unique b2 Zn such that a +n b ´n 0. We denote this inverse by “–

a”.

It is trivial to calculate: “-a” = (n-a).

Page 77: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

The multiplicative inverse of a2 Zn* is

the unique b2 Zn* such that

a *n b ´n 1. We denote this inverse by “a-1” or “1/a”.

The unique inverse of a must exist because the a row contains a permutation of the

elements and hence contains a unique 1.* 1 b 3 4

1 1 2 3 4

2 2 4 1 3

a 3 1 4 2

4 4 3 2 1

Page 78: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

The multiplicative inverse of a2 Zn* is the unique b2

Zn* such that

a *n b ´n 1. We denote this inverse by “a-1” or “1/a”.

Efficient algorithm to compute a-1 from a and n.

Execute the Extended Euclidean Algorithm on a and n. It will give two integers r and s

such that:ra + sn = (a,n) = 1

Taking both sides mod n, we obtain:rn ´n 1

Output r, which is the inverse of a

Page 79: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Zn = {0, 1, 2, …, n-1}Zn

* = {x 2 Zn | GCD(x,n) =1}

Define +n and *n:

a +n b = (a+b mod n) a *n b = (a*b mod n)

c *n ( a +n b) ´n (c *n a) +n (c*n b)

<Zn, +n>1. Closed2. Associative3. 0 is identity4. Additive Inverses5. Cancellation6. Commutative

<Zn*, *n>

1. Closed2. Associative3. 1 is identity4. Multiplicative Inverses5. Cancellation6. Commutative

Page 80: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Fundamental lemma of powers?

If (a ´n b) Then xa ´n xb ?

Page 81: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

If (a ´n b) Then xa ´n xb ?

NO!

(16 ´15 1) , but it is not the case that: 21 ´15 216

Page 82: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

By the permutation property, two names for the

same set:

Zn* = Zn

a

Zna = {a *n x | x 2 Zn

*}, a2 Zn*

* b 2 c 4

1 1 2 3 4

2 2 4 1 3

a 3 1 4 2

4 4 3 2 1

Page 83: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Two products on the same set:

Zn* = Zn

a

Zna = {a *n x | x 2 Zn

*}, a2 Zn*

x ´n ax [as x ranges over Zn* ]

x ´n x (asize of Zn*) [Commutativity]

1 = asize of Zn* [Cancellation] a(n) = 1

Page 84: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Euler’s Theorem

a2 Zn*, a(n) ´n 1

Fermat’s Little Theorem

p prime, a2 Zp*) ap-1 ´p 1

Page 85: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Fundamental lemma of powers.

Suppose x2 Zn*, and a,b,n are naturals.

If a ´(n) b Then xa ´n xb

Equivalently,xa mod (n) ´n xb mod (n)

Page 86: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Calculate ab mod n:

Use the repeated squaring method to compute a, a2, a4, …

But take exponents modulo (n)

Page 87: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Defining negative powers.

Suppose x2 Zn*, and a,n are naturals.

x-a is defined to be the multiplicative inverse of

Xa

X-a = (Xa)-1

Page 88: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Rule of integer exponents

Suppose x,y2 Zn*, and a,b are integers.

(xy)-1 ´n x-1 y-1

Xa Xb ´n Xa+b

Page 89: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Lemma of integer powers.

Suppose x2 Zn*, and a,b are integers.

If a ´(n) b Then xa ´n xb

Equivalently,xa mod (n) ´n xb mod (n)

Page 90: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Zn = {0, 1, 2, …, n-1}Zn

* = {x 2 Zn | GCD(x,n) =1}

Quick raising to power.

<Zn, +n>1. Closed2. Associative3. 0 is identity4. Additive Inverses

Fast + and -5. Cancellation6. Commutative

<Zn*, *n>

1. Closed2. Associative3. 1 is identity4. Multiplicative Inverses

Fast * and /5. Cancellation6. Commutative

Page 91: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Euler Phi Function

(n) = size of zn*

p prime ) Zp*= {1,2,3,…,p-1}

) (p) = p-1

(pq) = (p-1)(q-1) if p,q distinct primes

Page 92: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

The RSA Cryptosystem

Rivest, Shamir, and Adelman (1978)

RSA is one of the most used cryptographic protocols on the net. Your browser uses it to establish a

secure session with a site.

Page 93: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

Pick secret, random k-bit primes: p,q “Publish”: n = p*q (n) = (p) (q) = (p-1)*(q-1)

Pick random e Z*(n)

“Publish”: eCompute d = inverse of e in Z*

(n)

Hence, e*d = 1 [ mod (n) ]

“Private Key”: d

Page 94: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

n,e is my public key.

Use it to send a message to

me.

p,q random primes, e random Z*(n)

n = p*qe*d = 1 [ mod (n) ]

Page 95: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

n,e

p,q prime, e random Z*(n)

n = p*qe*d = 1 [ mod (n) ]

m

Page 96: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

n,e

p,q prime, e random Z*(n)

n = p*qe*d = 1 [ mod (n) ]

m

me [mod n]

Page 97: Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS 15-251 Fall 2005 Lecture 9Sept 27, 2005Carnegie

n,e

p,q prime, e random Z*(n)

n = p*qe*d = 1 [ mod (n) ]

m

me [mod n]

(me)d ´n m