RSA Algorithm
RSA Algorithm
(Rivest-Shamir-Adleman)
CCF3252
PRESENTED BY;
FARHIYA ALI CT206/111622/22
DAVID WAWERU CT206/202346/22
SILVIA MUNENE CT206/109336/22
JOSEPH MAARA CT206/109461/22
JOY KIRIMI CT206/109474/22
1
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…
… but nobody could decrypt messages without Bob’s private
key 2
Implementation
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
Using the privateKey, Bob has a function G that will allow him
to compute
3
M = G(C, privateKey) quickly
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 4
d
Example: Let’s take the message M = 1098 and encrypt it using the key e = 13
and
n = 17947 = 131 · 137
5
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)...
6
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)
In order to get our decryption function G, we need to show that this implies that
C d ≡ M (mod n)
8
Which gives (modulo p):
C d ≡ M · ((M (p-1))(q-1)) k ≡ M · 1(q-1) k ≡ M (mod p)
So we have:
C d ≡ M (mod p) x≡ M
(mod p)
C d ≡ M (mod q) ⇒ (which looks awfully familiar) ⇒ x ≡ M
(mod q)
where x = C d is a solution to a system of congruences.
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:
9
C d ≡ M (mod n)
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.
10
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
So, by Bezout’s Theorem and “climbing back up” the Euclidean algorithm, we
find that the inverse of e = 13 modulo 2436 is d = 937
11
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
12
Getting back to practical application: Okay, so why can’t we break RSA?
… and it turns out that factoring large products of primes is hard. There’s
only one answer and lots of numbers to sift through.
13
Cont……… Okay, so why can’t we break RSA?
14
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
15
Tidbit: Block ciphers
Question: Why?
16
Example: S’pose we wanted to send the message HELP
Let’s encrypt HELP using the keys from the previous example (e = 13,
d = 937, n = 2537)
17
Example: Encrypt HELP using the keys from the previous
example (e = 13, d = 937, n = 2537)
18
Example2: Decrypt C = 1188 1346 using the keys from the
previous example
(e = 13, d = 937, n = 2537)
19
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
20
hints!
070413 mod 2537 ≡ … ≡ 981 (mod 2537)
22