Cryptogrophy
Cryptogrophy
Cryptogrophy
Spring 2018
Alexandra Kolla
2
What did we do last time?
Today:
● Putting a ton of number theory
stuff together: RSA!
3
Cryptography
The sender and receiver both need to know the keys (k or a and b)
4
Cryptography
Allows senders and receivers to determine secret keys by transferring public information
completely in the open
5
Cryptography
6
Cryptography - RSA
Basic idea:
● Alice wants to send a message M to Bob that she doesn’t want anyone else to read
● In a public key system, Bob will send Alice (or anyone!) his public key and Alice will use
it to encrypt the message M as a cipher C
● When Bob receives the message, he decrypts it using his private key
● Anyone in the world could intercept the public key and use it to encrypt message…
7
Cryptography - RSA
Implementation in practice:
● We want to create a one-way function F that, given a message M and publicKey,
encrypts M as C = F(M, publicKey)
● The function F is called “one-way” because
○ Given M and publicKey, it is easy to compute C = F(m, publicKey)
to encrypt M
○ But if someone intercepts C and publicKey, it is extremely difficult to
invert F and compute M = F-1(C, publicKey)
● If it’s so hard to invert F, how is it that Bob can do it?
○ Using the privateKey, Bob has a function G that will allow him to compute
M = G(C, privateKey) quickly
8
Implementation in practice:
● So our scheme should give us function F and G such that
○ F is easy to compute (using publicKey) but very difficult to invert, unless…
○ … you know privateKey, then G is easy to compute and inverts F
RSA uses a huge number n that is the product of two huge primes, p and q (~200 digits)
● Encryption:
○ The public key is a pair of numbers (e, n)
○ Each message M is assumed to be a number between 0 and n-1
○ We encrypt a message by computing C = M e mod n
○ … which we can do quickly with fast modular exponentiation
● Decryption:
○ The private key is another pair of numbers (d, n) that relies on knowing p and q
○ We decrypt a message by computing M = Cd mod n,
where d is inverse of c (mod (p-1)(q-1)) 9
Implementation in practice:
● So our scheme should give us function F and G such that
○ F is easy to compute (using publicKey) but very difficult to invert, unless…
○ … you know privateKey, then G is easy to compute and inverts F
RSA uses a huge number n that is the product of two huge primes, p and q (~200 digits)
● Encryption:
○ The public key is a pair of numbers (e, n)
○ Each message M is assumed to be a number between 0 and n-1
○ We encrypt a message by computing C = M e mod n
○ … which we can do quickly with fast modular exponentiation
● Decryption:
○ The private key is another pair of numbers (d, n) that relies on knowing p and q
○ We decrypt a message by computing M = Cd mod n,
where d is inverse of e (mod (p-1)(q-1)) 10
Cryptography - RSA
Example: Let’s make up our own RSA scheme to send messages!
Public keys
11
Cryptography - RSA
Example: Let’s take the message M = 1098 and encrypt it using the key e = 13 and
n = 17947 = 131 · 137
12
Cryptography - RSA
Example: Let’s take the message M = 1098 and encrypt it using the key e = 13 and
n = 17947 = 131 · 137
13
Cryptography - RSA
Example: Let’s take the message M = 1098 and encrypt it using the key e = 13 and
n = 17947 = 131 · 137
14
Cryptography - RSA
If an unintended recipient sees the encoded message C and the public key (e, n), it would be
extremely difficult for them to find M
Now the idea is to find a private key (d, n) that decrypts the message via:
C d mod n = M
● And we need to figure out how to find such a pair (e, d), where it’s hard to discover d if you
know (e, n)...
15
Cryptography - RSA
● Let’s make some assumptions about our keys (public and private), and see how they can
lead to an unbreakable cryptosystem (at least by today’s standards)
Assumptions:
1. n = pq , where p and q are very large primes (~200+ digits)
2. e is a number that is relatively prime to (p-1)(q-1)
3. d is the inverse of e (mod (p-1)(q-1)) (which must exist from #2, above)
16
Cryptography - RSA
Now this means that for some integer k, we have that
In order to get our decryption function G, we need to show that this implies that
C d ≡ M (mod n)
This is valid except
Assume that gcd(M, p) = 1 and gcd(M, q) = 1. when your message M
is a multiple of p or q,
Then Fermat’s Little Theorem tells us that which is very rare.
So we have:
C d ≡ M (mod p) x ≡ M (mod p)
Since p and q are relatively prime (actually, both are prime), the Chinese Remainder
Theorem tells us that it is a unique solution modulo pq = n. Thus:
C d ≡ M (mod n)
18
Cryptography - RSA
Getting back to practical application: What does Bob need to do?
Note: Large primes p and q can be found quickly with probabilistic guess-and-checking.
19
Cryptography - RSA
Getting back to practical application: What does Bob need to do?
Note: Large primes p and q can be found quickly with probabilistic guess-and-checking.
20
Cryptography - RSA
Getting back to practical application: What does Bob need to do?
Note: Large primes p and q can be found quickly with probabilistic guess-and-checking.
21
Cryptography - RSA
Getting back to practical application: What does Bob need to do?
Note: Large primes p and q can be found quickly with probabilistic guess-and-checking.
Note: This only enables Alice to send Bob secure messages! If Bob wants to send Alice secure
messages, then Alice needs to do the same.
22
Cryptography - RSA
Example: Encrypt and decrypt the message M = 1819 using a Public Key Encryption based on
p = 43, q = 59 and e = 13
23
Cryptography - RSA
Example: Encrypt and decrypt the message M = 1819 using a Public Key Encryption based on
p = 43, q = 59 and e = 13
Note that
2436= 13·187 + 5
13 = 5·2 + 3
5 = 3·1 + 2
3 = 2·1 + 1
24
Cryptography - RSA
Example: Encrypt and decrypt the message M = 1819 using a Public Key Encryption based on
p = 43, q = 59 and e = 13
Now we need to find the private key, d, which is the inverse of e = 13 modulo 2436
2436= 13·187 + 5
13 = 5·2 + 3
5 = 3·1 + 2
3 = 2·1 + 1
25
Cryptography - RSA
Example: Encrypt and decrypt the message M = 1819 using a Public Key Encryption based on
p = 43, q = 59 and e = 13
Now we need to find the private key, d, which is the inverse of e = 13 modulo 2436
26
Cryptography - RSA
Example: Encrypt and decrypt the message M = 1819 using a Public Key Encryption based on
p = 43, q = 59 and e = 13
Encryption: C = M e mod n =
Decryption: M = C d mod n =
27
Cryptography - RSA
Example: Encrypt and decrypt the message M = 1819 using a Public Key Encryption based on
p = 43, q = 59 and e = 13
Encryption: C = M e mod n = 181913 mod 2537 = (using fast mod. exp.) = 2081
Decryption: M = C d mod n = 2081937 mod 2537 = (using fast mod. exp.) = 1819
● Without knowing how n is factored into n = pq, we have no idea that we have to look for an
inverse modulo (p-1)(q-1)
● … and it turns out that factoring large products of primes is hard. There’s only one answer
and a s***load lots of numbers to sift through.
● In 2009, researchers successfully factored a 232 decimal digit product of two primes
○ It took two years running in parallel on hundreds of machines.
○ The equivalent of 2000 years running on a single-core machine.
30
Cryptography - RSA
Getting back to practical application: Okay, so why can’t we break RSA?
That being said… A lock is only secure if you actually use it properly
[2]
31
Cryptography - more tidbits
Block ciphers
When we translate our message M into a number, we need to be careful that the numerical
representation of M does not exceed n
Question: Why?
Answer: If M exceeds n, then we would be unable to distinguish between M and any other
message that is congruent to M mod n
Typically, we break the message up into blocks (hence, block cipher), then encode the blocks
as digits, and then encrypt the blocks
32
Cryptography - more tidbits
Example: S’pose we wanted to send the message HELP
● Blocks of 2 letters works for n ≥ 2525 (first “25” represents first letter, …)
● Blocks of 3 letters would work with n ≥ 252525
● And so on…
Let’s encrypt HELP using the keys from the previous example (e = 13, d = 937, n = 2537)
33
Cryptography - more tidbits
Example: Encrypt HELP using the keys from the previous example (e = 13, d = 937, n = 2537)
HE = 070413 mod 2537 ≡ (FYOG: fast mod. exp.) ≡ 981 (mod 2537)
LP = 111513 mod 2537 ≡ (FYOG: fast mod. exp.) ≡ 461 (mod 2537)
34
Cryptography - more tidbits
Example: Decrypt C = 1188 1346 using the keys from the previous example
(e = 13, d = 937, n = 2537)
Convention: If your message doesn’t fit perfectly into your block size, then you pad the end of
the last block with X’s
35
Cryptography - more tidbits
Recap:
● RSA public key encryption:
○ You give everyone your publicKey (e, n) so they can encrypt messages to you
○ You know what the 2 primes p and q such that n = pq…
○ … So you know what d is (the inverse of e modulo (p-1)(q-1)) …
○ … So you can invert the encrypted messages without spending >thousands of years
throwing CPUs at it
Next time:
● We get inductive!
36
FYOG: hints!
070413 mod 2537 ≡ … ≡ 981 (mod 2537)
37