RSA Algorithm
RSA algorithm (named after its founders, Ron Rivest, Adi Shamir, and Leonard
Adleman) has become almost synonymous with public key cryptography.
Let’s first see how RSA works, and then examine why it works.
Choice of Bob’s public and private keys
:
1.
Choose two large prime numbers, p and q.
(Larger the values, the more difficult it is to break RSA, and the longer it takes to encode/decode. It is recommended that the product of p and q be on the order of 1024 bits for corporate use and 768 bits for use with “less valuable information”. For a discussion on how to find large prime numbers, see http://www.utm.edu/research/primes/prove/ ).
2.
Compute n = pq and z = (p-1)(q-1).
3.
Choose a number, e, less than n, which has no common factors (other than 1) with z.
(In this case, e and z are said to be relatively prime. The letter e is used since this value will be used in encryption).
4.
Find a number, d, such that ed-1 is exactly divisible (that is, with no remainder) by z.
(The letter d is used because this value will be used in decryption. Put another way, given e, we choose d such that the integer remainder when ed is divided by z is 1. The integer remainder when an integer x is divided by the integer n, is denoted as x mod n).
5.
K
B
+ = (n, e); K
B
= (n, d)
RSA’s Encryption/Decryption Algorithm
:
Suppose Alice wants to send Bob a bit pattern, or number, m such that m < n.
To encrypt the message, Alice uses Bob’s public key and determines the cipher text, c as: c = m e mod n
To decrypt the message, Bob uses Bob’s private key and determines the plain text, m as: m = c d mod n.
BA483: Class Participation Exercise: Application of RSA Algorithm
Date: Name(s):
Background:
Assume Bob has selected the prime numbers p and q as 5 and 7 respectively. Assume
Bob has selected e to be the number 5.
Assume Alice and Bob interpret each letter in the English alphabet as a number between
1 and 26. That is, a = 1, b = 2, …, n = 14,…, z = 26.
Assume Alice wishes to send the plaintext “love” to Bob, after encrypting using RSA.
Question : a) Compute Bob’s public key using RSA. b)
Determine Alice’s cipher text using RSA algorithm.
Example (with small values for p and q) :
1.
Suppose Bob chooses p = 5, and q = 7.
2.
Compute n = pq =35, and z = (p-1)(q-1) = (4)(6) = 24
3.
Bob chooses e = 5; Note 5 and 24 have no common factors.
4.
Bob chooses d = 29; Note (ed-1) = (5x29 -1) = (145-1) = 144 is exactly divisible by z =24 (as 24 x 6 = 144)
5.
Bob’s public key is given by K
B
+
= (n, e) = (35, 5);
Bob’s private key is given by K
B
-
= (n, d) = (35, 29)
Suppose Alice and Bob interpret each letter as a number between 1 and 26.
That is, a = 1, b = 2, c = 3,…, n = 14,…, z = 26.
Assume plain text is: Love
Alice’s RSA encryption with e = 5, and n =35 is as follows:
Plaintext letter m (numeric m e c = m e
mod n l o representation)
12
15
248832
759375
17
15 v e
22
5
Cipher text is: 17152210
Bob’s decryption with d = 29, and n = 35 is as follows:
Ciphertext c d
5153632
3125
22
10
17
15
22
481968572106750915091411825223071697
12783403948858939111232757568359375
851643319086537701956194499721106030592 m = c d
mod n Plaintext
12 letter l
15
22 o v e 10 100000000000000000000000000000
Why does RSA work?
Thanks to an amazing result from number theory that states the following:
If p and q are prime, and n = pq, then x y mod n = x (ymod(p-1)(q-1)) mod n
5
This rule implies that (m e ) d mod n = m because, as per number theory rule
(m e ) d mod n = m (ed(mod(p-1)(q-1)) mod n
= m 1 mod n (as the integer remainder when ed is divided by z is 1 )
= m
Similarly, (m d ) e mod n = m.