discrete mathematics & mathematical reasoning

58
Discrete Mathematics & Mathematical Reasoning Multiplicative Inverses and Some Cryptography Colin Stirling Informatics Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 1 / 13

Upload: others

Post on 11-Apr-2022

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Discrete Mathematics & Mathematical Reasoning

Discrete Mathematics & Mathematical ReasoningMultiplicative Inverses and Some Cryptography

Colin Stirling

Informatics

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 1 / 13

Page 2: Discrete Mathematics & Mathematical Reasoning

Multiplicative inverses

Every real number x , except x = 0, has a multiplicative inversey = 1

x ; so xy = 1

Similarly for x mod m, except x = 0, we wish to find y mod msuch that xy ≡ 1 (mod m)

x = 8 and m = 15. Then x 2 = 16 ≡ 1 (mod 15), so 2 is amultiplicative inverse of 8 (mod 15)

x = 12 and m = 15The sequence {xa (mod m) | a = 0,1,2, ...} is periodic, and takeson the values {0,12,9,6,3}. So, 12 has no multiplicative inversemod 15Notice gcd(8,15) = 1 whereas gcd(12,15) = 3

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 2 / 13

Page 3: Discrete Mathematics & Mathematical Reasoning

Multiplicative inverses

Every real number x , except x = 0, has a multiplicative inversey = 1

x ; so xy = 1

Similarly for x mod m, except x = 0, we wish to find y mod msuch that xy ≡ 1 (mod m)

x = 8 and m = 15. Then x 2 = 16 ≡ 1 (mod 15), so 2 is amultiplicative inverse of 8 (mod 15)

x = 12 and m = 15The sequence {xa (mod m) | a = 0,1,2, ...} is periodic, and takeson the values {0,12,9,6,3}. So, 12 has no multiplicative inversemod 15Notice gcd(8,15) = 1 whereas gcd(12,15) = 3

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 2 / 13

Page 4: Discrete Mathematics & Mathematical Reasoning

Multiplicative inverses

Every real number x , except x = 0, has a multiplicative inversey = 1

x ; so xy = 1

Similarly for x mod m, except x = 0, we wish to find y mod msuch that xy ≡ 1 (mod m)

x = 8 and m = 15. Then x 2 = 16 ≡ 1 (mod 15), so 2 is amultiplicative inverse of 8 (mod 15)

x = 12 and m = 15The sequence {xa (mod m) | a = 0,1,2, ...} is periodic, and takeson the values {0,12,9,6,3}. So, 12 has no multiplicative inversemod 15Notice gcd(8,15) = 1 whereas gcd(12,15) = 3

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 2 / 13

Page 5: Discrete Mathematics & Mathematical Reasoning

Multiplicative inverses

Every real number x , except x = 0, has a multiplicative inversey = 1

x ; so xy = 1

Similarly for x mod m, except x = 0, we wish to find y mod msuch that xy ≡ 1 (mod m)

x = 8 and m = 15. Then x 2 = 16 ≡ 1 (mod 15), so 2 is amultiplicative inverse of 8 (mod 15)

x = 12 and m = 15

The sequence {xa (mod m) | a = 0,1,2, ...} is periodic, and takeson the values {0,12,9,6,3}. So, 12 has no multiplicative inversemod 15Notice gcd(8,15) = 1 whereas gcd(12,15) = 3

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 2 / 13

Page 6: Discrete Mathematics & Mathematical Reasoning

Multiplicative inverses

Every real number x , except x = 0, has a multiplicative inversey = 1

x ; so xy = 1

Similarly for x mod m, except x = 0, we wish to find y mod msuch that xy ≡ 1 (mod m)

x = 8 and m = 15. Then x 2 = 16 ≡ 1 (mod 15), so 2 is amultiplicative inverse of 8 (mod 15)

x = 12 and m = 15The sequence {xa (mod m) | a = 0,1,2, ...} is periodic, and takeson the values {0,12,9,6,3}. So, 12 has no multiplicative inversemod 15

Notice gcd(8,15) = 1 whereas gcd(12,15) = 3

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 2 / 13

Page 7: Discrete Mathematics & Mathematical Reasoning

Multiplicative inverses

Every real number x , except x = 0, has a multiplicative inversey = 1

x ; so xy = 1

Similarly for x mod m, except x = 0, we wish to find y mod msuch that xy ≡ 1 (mod m)

x = 8 and m = 15. Then x 2 = 16 ≡ 1 (mod 15), so 2 is amultiplicative inverse of 8 (mod 15)

x = 12 and m = 15The sequence {xa (mod m) | a = 0,1,2, ...} is periodic, and takeson the values {0,12,9,6,3}. So, 12 has no multiplicative inversemod 15Notice gcd(8,15) = 1 whereas gcd(12,15) = 3

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 2 / 13

Page 8: Discrete Mathematics & Mathematical Reasoning

Multiplicative inverses mod m when gcd(m, x) = 1

TheoremIf m, x are positive integers and gcd(m, x) = 1 then x has amultiplicative inverse mod m (and it is unique mod m)

Proof.By Bézout’s theorem there are s and t such that

sm + tx = 1 = gcd(m, x)

So, sm + tx ≡ 1 (mod m). As sm ≡ 0 (mod m), so tx ≡ 1(mod m).For uniqueness mod m. Assume tx ≡ 1 (mod m) and ux ≡ 1 (mod m).Therefore, tx ≡ ux (mod m). Since gcd(m, x) = 1 it follows thatt ≡ u (mod m).

Compute the multiplicative inverse using extended euclidean algorithm

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 3 / 13

Page 9: Discrete Mathematics & Mathematical Reasoning

Multiplicative inverses mod m when gcd(m, x) = 1

TheoremIf m, x are positive integers and gcd(m, x) = 1 then x has amultiplicative inverse mod m (and it is unique mod m)

Proof.By Bézout’s theorem there are s and t such that

sm + tx = 1 = gcd(m, x)

So, sm + tx ≡ 1 (mod m). As sm ≡ 0 (mod m), so tx ≡ 1(mod m).For uniqueness mod m. Assume tx ≡ 1 (mod m) and ux ≡ 1 (mod m).Therefore, tx ≡ ux (mod m). Since gcd(m, x) = 1 it follows thatt ≡ u (mod m).

Compute the multiplicative inverse using extended euclidean algorithm

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 3 / 13

Page 10: Discrete Mathematics & Mathematical Reasoning

Multiplicative inverses mod m when gcd(m, x) = 1

TheoremIf m, x are positive integers and gcd(m, x) = 1 then x has amultiplicative inverse mod m (and it is unique mod m)

Proof.By Bézout’s theorem there are s and t such that

sm + tx = 1 = gcd(m, x)

So, sm + tx ≡ 1 (mod m). As sm ≡ 0 (mod m), so tx ≡ 1(mod m).For uniqueness mod m. Assume tx ≡ 1 (mod m) and ux ≡ 1 (mod m).Therefore, tx ≡ ux (mod m). Since gcd(m, x) = 1 it follows thatt ≡ u (mod m).

Compute the multiplicative inverse using extended euclidean algorithm

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 3 / 13

Page 11: Discrete Mathematics & Mathematical Reasoning

Chinese remainder theorem

TheoremLet m1,m2, . . . ,mn be pairwise relatively prime positive integersgreater than 1 and a1,a2, . . . ,an be arbitrary integers. Then the system

x ≡ a1 (mod m1)x ≡ a2 (mod m2)...x ≡ an (mod mn)

has a unique solution modulo m = m1m2 · · ·mn

Proof.In the book

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 4 / 13

Page 12: Discrete Mathematics & Mathematical Reasoning

Chinese remainder theorem

TheoremLet m1,m2, . . . ,mn be pairwise relatively prime positive integersgreater than 1 and a1,a2, . . . ,an be arbitrary integers. Then the system

x ≡ a1 (mod m1)x ≡ a2 (mod m2)...x ≡ an (mod mn)

has a unique solution modulo m = m1m2 · · ·mn

Proof.In the book

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 4 / 13

Page 13: Discrete Mathematics & Mathematical Reasoning

Example

x ≡ 2 (mod 3)x ≡ 3 (mod 5)x ≡ 5 (mod 7)

m = 3 · 5 · 7 = 105M1 = 35 and 2 is an inverse of M1 mod 3M2 = 21 and 1 is an inverse of M2 mod 5M3 = 15 and 1 is an inverse of M3 mod 7x = 2 · 35 · 2 + 3 · 21 · 1 + 5 · 15 · 1x = 140 + 63 + 75 = 278 ≡ 68 (mod 105)

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 5 / 13

Page 14: Discrete Mathematics & Mathematical Reasoning

Example

x ≡ 2 (mod 3)x ≡ 3 (mod 5)x ≡ 5 (mod 7)

m = 3 · 5 · 7 = 105

M1 = 35 and 2 is an inverse of M1 mod 3M2 = 21 and 1 is an inverse of M2 mod 5M3 = 15 and 1 is an inverse of M3 mod 7x = 2 · 35 · 2 + 3 · 21 · 1 + 5 · 15 · 1x = 140 + 63 + 75 = 278 ≡ 68 (mod 105)

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 5 / 13

Page 15: Discrete Mathematics & Mathematical Reasoning

Example

x ≡ 2 (mod 3)x ≡ 3 (mod 5)x ≡ 5 (mod 7)

m = 3 · 5 · 7 = 105M1 = 35 and 2 is an inverse of M1 mod 3

M2 = 21 and 1 is an inverse of M2 mod 5M3 = 15 and 1 is an inverse of M3 mod 7x = 2 · 35 · 2 + 3 · 21 · 1 + 5 · 15 · 1x = 140 + 63 + 75 = 278 ≡ 68 (mod 105)

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 5 / 13

Page 16: Discrete Mathematics & Mathematical Reasoning

Example

x ≡ 2 (mod 3)x ≡ 3 (mod 5)x ≡ 5 (mod 7)

m = 3 · 5 · 7 = 105M1 = 35 and 2 is an inverse of M1 mod 3M2 = 21 and 1 is an inverse of M2 mod 5

M3 = 15 and 1 is an inverse of M3 mod 7x = 2 · 35 · 2 + 3 · 21 · 1 + 5 · 15 · 1x = 140 + 63 + 75 = 278 ≡ 68 (mod 105)

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 5 / 13

Page 17: Discrete Mathematics & Mathematical Reasoning

Example

x ≡ 2 (mod 3)x ≡ 3 (mod 5)x ≡ 5 (mod 7)

m = 3 · 5 · 7 = 105M1 = 35 and 2 is an inverse of M1 mod 3M2 = 21 and 1 is an inverse of M2 mod 5M3 = 15 and 1 is an inverse of M3 mod 7

x = 2 · 35 · 2 + 3 · 21 · 1 + 5 · 15 · 1x = 140 + 63 + 75 = 278 ≡ 68 (mod 105)

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 5 / 13

Page 18: Discrete Mathematics & Mathematical Reasoning

Example

x ≡ 2 (mod 3)x ≡ 3 (mod 5)x ≡ 5 (mod 7)

m = 3 · 5 · 7 = 105M1 = 35 and 2 is an inverse of M1 mod 3M2 = 21 and 1 is an inverse of M2 mod 5M3 = 15 and 1 is an inverse of M3 mod 7x = 2 · 35 · 2 + 3 · 21 · 1 + 5 · 15 · 1

x = 140 + 63 + 75 = 278 ≡ 68 (mod 105)

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 5 / 13

Page 19: Discrete Mathematics & Mathematical Reasoning

Example

x ≡ 2 (mod 3)x ≡ 3 (mod 5)x ≡ 5 (mod 7)

m = 3 · 5 · 7 = 105M1 = 35 and 2 is an inverse of M1 mod 3M2 = 21 and 1 is an inverse of M2 mod 5M3 = 15 and 1 is an inverse of M3 mod 7x = 2 · 35 · 2 + 3 · 21 · 1 + 5 · 15 · 1x = 140 + 63 + 75 = 278 ≡ 68 (mod 105)

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 5 / 13

Page 20: Discrete Mathematics & Mathematical Reasoning

Fermat’s little theorem

TheoremIf p is prime and p 6 |a, then ap−1 ≡ 1 (mod p). Furthermore, for everyinteger a we have ap ≡ a (mod p)

Proof.Assume p 6 |a and so, therefore, gcd(p,a) = 1. Then a,2a, . . . , (p − 1)aare not pairwise congruent modulo p; if ia ≡ ja (mod p) becausegcd(p,a) = 1 then i ≡ j (mod p) which is impossible. Therefore, eachelement ja mod p is a distinct element in the set {1, . . . ,p − 1}. Thismeans that the product a · 2a · · · (p − 1)a ≡ 1 · 2 · · · p − 1 (mod p).Therefore, (p − 1)!ap−1 ≡ (p − 1)! (mod p). Now becausegcd(p,q) = 1 for 1 ≤ q ≤ p − 1 it follows that ap−1 ≡ 1 (mod p).Therefore, also ap ≡ a (mod p) and when p|a then clearlyap ≡ a (mod p).

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 6 / 13

Page 21: Discrete Mathematics & Mathematical Reasoning

Fermat’s little theorem

TheoremIf p is prime and p 6 |a, then ap−1 ≡ 1 (mod p). Furthermore, for everyinteger a we have ap ≡ a (mod p)

Proof.Assume p 6 |a and so, therefore, gcd(p,a) = 1. Then a,2a, . . . , (p − 1)aare not pairwise congruent modulo p; if ia ≡ ja (mod p) becausegcd(p,a) = 1 then i ≡ j (mod p) which is impossible. Therefore, eachelement ja mod p is a distinct element in the set {1, . . . ,p − 1}. Thismeans that the product a · 2a · · · (p − 1)a ≡ 1 · 2 · · · p − 1 (mod p).Therefore, (p − 1)!ap−1 ≡ (p − 1)! (mod p). Now becausegcd(p,q) = 1 for 1 ≤ q ≤ p − 1 it follows that ap−1 ≡ 1 (mod p).Therefore, also ap ≡ a (mod p) and when p|a then clearlyap ≡ a (mod p).

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 6 / 13

Page 22: Discrete Mathematics & Mathematical Reasoning

Computing the remainders modulo prime p

Find 7222 mod 11

By Fermat’s little theorem, we know that 710 ≡ 1 (mod 11), and so(710)k ≡ 1 (mod 11) for every positive integer k . Therefore,7222 = 722·10+2 = (710)22 72 ≡ 12249 ≡ 5 (mod 11). Hence,7222 mod 11 = 5

2340 ≡ 1 (mod 11) because 210 ≡ 1 (mod 11)

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 7 / 13

Page 23: Discrete Mathematics & Mathematical Reasoning

Computing the remainders modulo prime p

Find 7222 mod 11

By Fermat’s little theorem, we know that 710 ≡ 1 (mod 11), and so(710)k ≡ 1 (mod 11) for every positive integer k . Therefore,7222 = 722·10+2 = (710)22 72 ≡ 12249 ≡ 5 (mod 11). Hence,7222 mod 11 = 5

2340 ≡ 1 (mod 11) because 210 ≡ 1 (mod 11)

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 7 / 13

Page 24: Discrete Mathematics & Mathematical Reasoning

Computing the remainders modulo prime p

Find 7222 mod 11

By Fermat’s little theorem, we know that 710 ≡ 1 (mod 11), and so(710)k ≡ 1 (mod 11) for every positive integer k . Therefore,7222 = 722·10+2 = (710)22 72 ≡ 12249 ≡ 5 (mod 11). Hence,7222 mod 11 = 5

2340 ≡ 1 (mod 11) because 210 ≡ 1 (mod 11)

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 7 / 13

Page 25: Discrete Mathematics & Mathematical Reasoning

Private key cryptography

Bob wants to send Alice a secret message M

Alice sends Bob a private key En (which has an inverse De)Bob encrypts M and sends Alice En(M)Alice decrypts En(M), De(En(M))Important property De(En(M)) = MAlice and Bob share a secret which could be intercepted by a thirdpartyExample use En(p) = (p + 3) mod 26What is WKLV LV D VHFUHW ?

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 8 / 13

Page 26: Discrete Mathematics & Mathematical Reasoning

Private key cryptography

Bob wants to send Alice a secret message MAlice sends Bob a private key En (which has an inverse De)

Bob encrypts M and sends Alice En(M)Alice decrypts En(M), De(En(M))Important property De(En(M)) = MAlice and Bob share a secret which could be intercepted by a thirdpartyExample use En(p) = (p + 3) mod 26What is WKLV LV D VHFUHW ?

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 8 / 13

Page 27: Discrete Mathematics & Mathematical Reasoning

Private key cryptography

Bob wants to send Alice a secret message MAlice sends Bob a private key En (which has an inverse De)Bob encrypts M and sends Alice En(M)

Alice decrypts En(M), De(En(M))Important property De(En(M)) = MAlice and Bob share a secret which could be intercepted by a thirdpartyExample use En(p) = (p + 3) mod 26What is WKLV LV D VHFUHW ?

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 8 / 13

Page 28: Discrete Mathematics & Mathematical Reasoning

Private key cryptography

Bob wants to send Alice a secret message MAlice sends Bob a private key En (which has an inverse De)Bob encrypts M and sends Alice En(M)Alice decrypts En(M), De(En(M))

Important property De(En(M)) = MAlice and Bob share a secret which could be intercepted by a thirdpartyExample use En(p) = (p + 3) mod 26What is WKLV LV D VHFUHW ?

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 8 / 13

Page 29: Discrete Mathematics & Mathematical Reasoning

Private key cryptography

Bob wants to send Alice a secret message MAlice sends Bob a private key En (which has an inverse De)Bob encrypts M and sends Alice En(M)Alice decrypts En(M), De(En(M))Important property De(En(M)) = M

Alice and Bob share a secret which could be intercepted by a thirdpartyExample use En(p) = (p + 3) mod 26What is WKLV LV D VHFUHW ?

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 8 / 13

Page 30: Discrete Mathematics & Mathematical Reasoning

Private key cryptography

Bob wants to send Alice a secret message MAlice sends Bob a private key En (which has an inverse De)Bob encrypts M and sends Alice En(M)Alice decrypts En(M), De(En(M))Important property De(En(M)) = MAlice and Bob share a secret which could be intercepted by a thirdparty

Example use En(p) = (p + 3) mod 26What is WKLV LV D VHFUHW ?

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 8 / 13

Page 31: Discrete Mathematics & Mathematical Reasoning

Private key cryptography

Bob wants to send Alice a secret message MAlice sends Bob a private key En (which has an inverse De)Bob encrypts M and sends Alice En(M)Alice decrypts En(M), De(En(M))Important property De(En(M)) = MAlice and Bob share a secret which could be intercepted by a thirdpartyExample use En(p) = (p + 3) mod 26

What is WKLV LV D VHFUHW ?

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 8 / 13

Page 32: Discrete Mathematics & Mathematical Reasoning

Private key cryptography

Bob wants to send Alice a secret message MAlice sends Bob a private key En (which has an inverse De)Bob encrypts M and sends Alice En(M)Alice decrypts En(M), De(En(M))Important property De(En(M)) = MAlice and Bob share a secret which could be intercepted by a thirdpartyExample use En(p) = (p + 3) mod 26What is WKLV LV D VHFUHW ?

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 8 / 13

Page 33: Discrete Mathematics & Mathematical Reasoning

Public key cryptography

Bob wants to send Alice a secret message M

Without Alice and Bob sharing a secretAlice sends Bob a public key En (and keeps her inverse privatekey De secret from everyone including Bob)Bob encrypts M and sends Alice En(M)Alice decrypts En(M), De(En(M))Important property De(En(M)) = MThe challenge: De can’t be feasibly computed from En; and givenEn(M) one can’t feasibly compute M

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 9 / 13

Page 34: Discrete Mathematics & Mathematical Reasoning

Public key cryptography

Bob wants to send Alice a secret message MWithout Alice and Bob sharing a secret

Alice sends Bob a public key En (and keeps her inverse privatekey De secret from everyone including Bob)Bob encrypts M and sends Alice En(M)Alice decrypts En(M), De(En(M))Important property De(En(M)) = MThe challenge: De can’t be feasibly computed from En; and givenEn(M) one can’t feasibly compute M

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 9 / 13

Page 35: Discrete Mathematics & Mathematical Reasoning

Public key cryptography

Bob wants to send Alice a secret message MWithout Alice and Bob sharing a secretAlice sends Bob a public key En (and keeps her inverse privatekey De secret from everyone including Bob)

Bob encrypts M and sends Alice En(M)Alice decrypts En(M), De(En(M))Important property De(En(M)) = MThe challenge: De can’t be feasibly computed from En; and givenEn(M) one can’t feasibly compute M

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 9 / 13

Page 36: Discrete Mathematics & Mathematical Reasoning

Public key cryptography

Bob wants to send Alice a secret message MWithout Alice and Bob sharing a secretAlice sends Bob a public key En (and keeps her inverse privatekey De secret from everyone including Bob)Bob encrypts M and sends Alice En(M)

Alice decrypts En(M), De(En(M))Important property De(En(M)) = MThe challenge: De can’t be feasibly computed from En; and givenEn(M) one can’t feasibly compute M

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 9 / 13

Page 37: Discrete Mathematics & Mathematical Reasoning

Public key cryptography

Bob wants to send Alice a secret message MWithout Alice and Bob sharing a secretAlice sends Bob a public key En (and keeps her inverse privatekey De secret from everyone including Bob)Bob encrypts M and sends Alice En(M)Alice decrypts En(M), De(En(M))

Important property De(En(M)) = MThe challenge: De can’t be feasibly computed from En; and givenEn(M) one can’t feasibly compute M

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 9 / 13

Page 38: Discrete Mathematics & Mathematical Reasoning

Public key cryptography

Bob wants to send Alice a secret message MWithout Alice and Bob sharing a secretAlice sends Bob a public key En (and keeps her inverse privatekey De secret from everyone including Bob)Bob encrypts M and sends Alice En(M)Alice decrypts En(M), De(En(M))Important property De(En(M)) = M

The challenge: De can’t be feasibly computed from En; and givenEn(M) one can’t feasibly compute M

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 9 / 13

Page 39: Discrete Mathematics & Mathematical Reasoning

Public key cryptography

Bob wants to send Alice a secret message MWithout Alice and Bob sharing a secretAlice sends Bob a public key En (and keeps her inverse privatekey De secret from everyone including Bob)Bob encrypts M and sends Alice En(M)Alice decrypts En(M), De(En(M))Important property De(En(M)) = MThe challenge: De can’t be feasibly computed from En; and givenEn(M) one can’t feasibly compute M

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 9 / 13

Page 40: Discrete Mathematics & Mathematical Reasoning

RSA Cryptosystem: Rivest, Shamir and Adleman

Choose two distinct prime numbers p and q

Let n = pq and k = (p − 1)(q − 1)

Choose integer e where 1 < e < k and gcd(e, k) = 1

(n,e) is released as the public key

Let d be the multiplicative inverse of e modulo k , sode ≡ 1 (mod k)

(n,d) is the private key and kept secret

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 10 / 13

Page 41: Discrete Mathematics & Mathematical Reasoning

RSA: encryption and decryption

Alice transmits her public key (n,e) to Bob and keeps the private key(n,d) secret

Encryption Bob wishes to send message M to Alice1 He turns M into integer m, 0 ≤ m < n, using an agreed-upon

reversible protocol known as a padding scheme2 He computes the ciphertext c corresponding to c = me mod n.

(This can be done quickly)3 Bob transmits c to Alice.

Decryption Alice can recover m from c1 Using her private key exponent d via computing m = cd mod n2 Given m, she can recover the original message M by reversing the

padding scheme

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 11 / 13

Page 42: Discrete Mathematics & Mathematical Reasoning

RSA: encryption and decryption

Alice transmits her public key (n,e) to Bob and keeps the private key(n,d) secret

Encryption Bob wishes to send message M to Alice

1 He turns M into integer m, 0 ≤ m < n, using an agreed-uponreversible protocol known as a padding scheme

2 He computes the ciphertext c corresponding to c = me mod n.(This can be done quickly)

3 Bob transmits c to Alice.

Decryption Alice can recover m from c1 Using her private key exponent d via computing m = cd mod n2 Given m, she can recover the original message M by reversing the

padding scheme

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 11 / 13

Page 43: Discrete Mathematics & Mathematical Reasoning

RSA: encryption and decryption

Alice transmits her public key (n,e) to Bob and keeps the private key(n,d) secret

Encryption Bob wishes to send message M to Alice1 He turns M into integer m, 0 ≤ m < n, using an agreed-upon

reversible protocol known as a padding scheme

2 He computes the ciphertext c corresponding to c = me mod n.(This can be done quickly)

3 Bob transmits c to Alice.

Decryption Alice can recover m from c1 Using her private key exponent d via computing m = cd mod n2 Given m, she can recover the original message M by reversing the

padding scheme

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 11 / 13

Page 44: Discrete Mathematics & Mathematical Reasoning

RSA: encryption and decryption

Alice transmits her public key (n,e) to Bob and keeps the private key(n,d) secret

Encryption Bob wishes to send message M to Alice1 He turns M into integer m, 0 ≤ m < n, using an agreed-upon

reversible protocol known as a padding scheme2 He computes the ciphertext c corresponding to c = me mod n.

(This can be done quickly)

3 Bob transmits c to Alice.

Decryption Alice can recover m from c1 Using her private key exponent d via computing m = cd mod n2 Given m, she can recover the original message M by reversing the

padding scheme

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 11 / 13

Page 45: Discrete Mathematics & Mathematical Reasoning

RSA: encryption and decryption

Alice transmits her public key (n,e) to Bob and keeps the private key(n,d) secret

Encryption Bob wishes to send message M to Alice1 He turns M into integer m, 0 ≤ m < n, using an agreed-upon

reversible protocol known as a padding scheme2 He computes the ciphertext c corresponding to c = me mod n.

(This can be done quickly)3 Bob transmits c to Alice.

Decryption Alice can recover m from c1 Using her private key exponent d via computing m = cd mod n2 Given m, she can recover the original message M by reversing the

padding scheme

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 11 / 13

Page 46: Discrete Mathematics & Mathematical Reasoning

RSA: encryption and decryption

Alice transmits her public key (n,e) to Bob and keeps the private key(n,d) secret

Encryption Bob wishes to send message M to Alice1 He turns M into integer m, 0 ≤ m < n, using an agreed-upon

reversible protocol known as a padding scheme2 He computes the ciphertext c corresponding to c = me mod n.

(This can be done quickly)3 Bob transmits c to Alice.

Decryption Alice can recover m from c

1 Using her private key exponent d via computing m = cd mod n2 Given m, she can recover the original message M by reversing the

padding scheme

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 11 / 13

Page 47: Discrete Mathematics & Mathematical Reasoning

RSA: encryption and decryption

Alice transmits her public key (n,e) to Bob and keeps the private key(n,d) secret

Encryption Bob wishes to send message M to Alice1 He turns M into integer m, 0 ≤ m < n, using an agreed-upon

reversible protocol known as a padding scheme2 He computes the ciphertext c corresponding to c = me mod n.

(This can be done quickly)3 Bob transmits c to Alice.

Decryption Alice can recover m from c1 Using her private key exponent d via computing m = cd mod n

2 Given m, she can recover the original message M by reversing thepadding scheme

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 11 / 13

Page 48: Discrete Mathematics & Mathematical Reasoning

RSA: encryption and decryption

Alice transmits her public key (n,e) to Bob and keeps the private key(n,d) secret

Encryption Bob wishes to send message M to Alice1 He turns M into integer m, 0 ≤ m < n, using an agreed-upon

reversible protocol known as a padding scheme2 He computes the ciphertext c corresponding to c = me mod n.

(This can be done quickly)3 Bob transmits c to Alice.

Decryption Alice can recover m from c1 Using her private key exponent d via computing m = cd mod n2 Given m, she can recover the original message M by reversing the

padding scheme

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 11 / 13

Page 49: Discrete Mathematics & Mathematical Reasoning

Example

n = 43 · 59 = 2537

gcd(13,42 · 58) = 1, so public key is (2537,13)d = 937 is inverse of 13 modulo 2436 = 42 · 58; private key(2537,937)Encrypt STOP as two blocks 1819 for ST and 1415 for OP(padding scheme: position in alphabet - 1)So, 181913 mod 2537 = 2081 and 141513 mod 2537 = 2182So encrypted message is 2081 2182Receive message 0981 0461: decrypt it0981937 mod 2537 = 0704 and 0461937 mod 2537 = 1115So decrypted message is HELP

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 12 / 13

Page 50: Discrete Mathematics & Mathematical Reasoning

Example

n = 43 · 59 = 2537gcd(13,42 · 58) = 1, so public key is (2537,13)

d = 937 is inverse of 13 modulo 2436 = 42 · 58; private key(2537,937)Encrypt STOP as two blocks 1819 for ST and 1415 for OP(padding scheme: position in alphabet - 1)So, 181913 mod 2537 = 2081 and 141513 mod 2537 = 2182So encrypted message is 2081 2182Receive message 0981 0461: decrypt it0981937 mod 2537 = 0704 and 0461937 mod 2537 = 1115So decrypted message is HELP

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 12 / 13

Page 51: Discrete Mathematics & Mathematical Reasoning

Example

n = 43 · 59 = 2537gcd(13,42 · 58) = 1, so public key is (2537,13)d = 937 is inverse of 13 modulo 2436 = 42 · 58; private key(2537,937)

Encrypt STOP as two blocks 1819 for ST and 1415 for OP(padding scheme: position in alphabet - 1)So, 181913 mod 2537 = 2081 and 141513 mod 2537 = 2182So encrypted message is 2081 2182Receive message 0981 0461: decrypt it0981937 mod 2537 = 0704 and 0461937 mod 2537 = 1115So decrypted message is HELP

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 12 / 13

Page 52: Discrete Mathematics & Mathematical Reasoning

Example

n = 43 · 59 = 2537gcd(13,42 · 58) = 1, so public key is (2537,13)d = 937 is inverse of 13 modulo 2436 = 42 · 58; private key(2537,937)Encrypt STOP as two blocks 1819 for ST and 1415 for OP(padding scheme: position in alphabet - 1)

So, 181913 mod 2537 = 2081 and 141513 mod 2537 = 2182So encrypted message is 2081 2182Receive message 0981 0461: decrypt it0981937 mod 2537 = 0704 and 0461937 mod 2537 = 1115So decrypted message is HELP

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 12 / 13

Page 53: Discrete Mathematics & Mathematical Reasoning

Example

n = 43 · 59 = 2537gcd(13,42 · 58) = 1, so public key is (2537,13)d = 937 is inverse of 13 modulo 2436 = 42 · 58; private key(2537,937)Encrypt STOP as two blocks 1819 for ST and 1415 for OP(padding scheme: position in alphabet - 1)So, 181913 mod 2537 = 2081 and 141513 mod 2537 = 2182

So encrypted message is 2081 2182Receive message 0981 0461: decrypt it0981937 mod 2537 = 0704 and 0461937 mod 2537 = 1115So decrypted message is HELP

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 12 / 13

Page 54: Discrete Mathematics & Mathematical Reasoning

Example

n = 43 · 59 = 2537gcd(13,42 · 58) = 1, so public key is (2537,13)d = 937 is inverse of 13 modulo 2436 = 42 · 58; private key(2537,937)Encrypt STOP as two blocks 1819 for ST and 1415 for OP(padding scheme: position in alphabet - 1)So, 181913 mod 2537 = 2081 and 141513 mod 2537 = 2182So encrypted message is 2081 2182

Receive message 0981 0461: decrypt it0981937 mod 2537 = 0704 and 0461937 mod 2537 = 1115So decrypted message is HELP

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 12 / 13

Page 55: Discrete Mathematics & Mathematical Reasoning

Example

n = 43 · 59 = 2537gcd(13,42 · 58) = 1, so public key is (2537,13)d = 937 is inverse of 13 modulo 2436 = 42 · 58; private key(2537,937)Encrypt STOP as two blocks 1819 for ST and 1415 for OP(padding scheme: position in alphabet - 1)So, 181913 mod 2537 = 2081 and 141513 mod 2537 = 2182So encrypted message is 2081 2182Receive message 0981 0461: decrypt it

0981937 mod 2537 = 0704 and 0461937 mod 2537 = 1115So decrypted message is HELP

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 12 / 13

Page 56: Discrete Mathematics & Mathematical Reasoning

Example

n = 43 · 59 = 2537gcd(13,42 · 58) = 1, so public key is (2537,13)d = 937 is inverse of 13 modulo 2436 = 42 · 58; private key(2537,937)Encrypt STOP as two blocks 1819 for ST and 1415 for OP(padding scheme: position in alphabet - 1)So, 181913 mod 2537 = 2081 and 141513 mod 2537 = 2182So encrypted message is 2081 2182Receive message 0981 0461: decrypt it0981937 mod 2537 = 0704 and 0461937 mod 2537 = 1115

So decrypted message is HELP

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 12 / 13

Page 57: Discrete Mathematics & Mathematical Reasoning

Example

n = 43 · 59 = 2537gcd(13,42 · 58) = 1, so public key is (2537,13)d = 937 is inverse of 13 modulo 2436 = 42 · 58; private key(2537,937)Encrypt STOP as two blocks 1819 for ST and 1415 for OP(padding scheme: position in alphabet - 1)So, 181913 mod 2537 = 2081 and 141513 mod 2537 = 2182So encrypted message is 2081 2182Receive message 0981 0461: decrypt it0981937 mod 2537 = 0704 and 0461937 mod 2537 = 1115So decrypted message is HELP

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 12 / 13

Page 58: Discrete Mathematics & Mathematical Reasoning

RSA: correctness of decryption

Given that c = me mod n, is m = cd mod n?

cd = (me)d ≡ med (mod n)

By construction, d and e are each others multiplicative inversesmodulo k , i.e. ed ≡ 1 (mod k). Also k = (p − 1)(q − 1). Thused − 1 = h(p − 1)(q − 1) for some integer h. We consider med mod pIf p 6 |m thenmed = mh(p−1)(q−1)m = (mp−1)h(q−1)m ≡ 1h(q−1)m ≡ m (mod p) (byFermat’s little theorem)Otherwise med ≡ 0 ≡ m (mod p)Symmetrically, med ≡ m (mod q)Since p, q are distinct primes, we have med ≡ m (mod pq). Sincen = pq, we have cd = med ≡ m (mod n)

Colin Stirling (Informatics) Discrete Mathematics (Chap 4) Today 13 / 13