3.6 RSA Cryptography Cryptography is the science of coding and decoding messages. Over the years many methods for coding messages have been developed. Many of them involve converting the text to numbers and using some algebraic method for coding the corresponding numbers. Quite a few of these methods involve modular arithmetic. In this section we look at the RSA cryptography method developed in the 1970's and named after Ron Rivest, Adi Shamir and Leonard Adleman. 3.6.1 The Method RSA cryptography is very simple in principle. If someone wants to send a message to you, they convert the text to a sequence m1, m2 …mR of numbers, raise each number to a power e and mod by another number n. (1) cj = (mj)e mod n j = 1, 2, …, R The coded message is then this new sequence of c1, c2 …cR of number which they send to you. To decode the message, you raise each of the numbers c1, c2 …cR in the coded message to the complementary power d and mod by the same number n. (2) mj = (cj)d mod n j = 1, 2, …, R The result is the original sequence m1, m2 …mR of numbers that you converts back to the original text. The numbers n and e are not arbitrary. In fact the method starts by you choosing two primes p and q and forming the number n = pq as the product of p and q. In practice, the primes are very large. Currently they each need to be at least 200 digits long. Then you choose the power e to be a number that has no factor in common with p – 1 and q – 1. Also e should be less than (p – 1)(q – 1). Finally, the complementary power d is the inverse of e mod (p – 1)(q – 1). You tell the world n and e. There is no secret to n and e. However, you keep the factorization of n as n = pq a secret. You also keep d a secret. With current factoring methods there is no way someone else can find the factorization of n and hence d in a reasonable amount of time. If someone wants to send you a confidential message, they convert the message to a sequence of numbers each less than n. Then they use (1) to code the sequence and send the coded sequence to you. They don't have to keep the coded sequence a secret either. 3.6.1 - 1 When you receive the message, you decode it using (2). No one else can decode it since they don't know d. Example 1. Let's do an example with small numbers to illustrate this. To begin with you need to choose two primes p and q. Since we are using small numbers, let's take p = 3 and q = 11. Then n = pq = (3)(11) = 33. Next we need to choose the power e so that it has no factor in common with p – 1 and q - 1. Here p – 1 = 2 and q - 1 = = 10. So e should have no factor in common with 2 and 10. In other words e should not have 2 or 5 as a factor. We can choose e = 3. Finally we choose d to be the inverse of e mod (p – 1)(q – 1). In this case (p - 1)(q - 1) = (2)(10) = 20. So d is the inverse of 3 mod 20. Thus d satisfies 3d mod 20 = 1. Ordinarily we would use the Euclidean algorithm to find d. However, in this case we can see that d = 7 since (3)(7) = 21 and 21 mod 20 = 1. We also have to decide on a method for converting the text of a message to numbers. Since this is just an illustrative example, let's do this as simply as possible. We convert each letter in the message to the number which is its position in the alphabet. Thus a is converted to 1, b to 2, and so on with z being converted to 26. Let's convert a space to 27. We tell the world n = 33, d = 3 and this method to convert text to a sequence of numbers. Now suppose someone wants to send you a confidential message. For example, suppose Sue wants to send you the message (3) go blue First she converts each letter to its position in the alphabet with a space being converted to 27. This gives the following sequence of numbers (4) m1, m2, m3, m4, m5, m6, m7 = 7, 15, 27, 2, 12, 21, 5 Next she codes each number mj using (1). For example c1 = (m1)e mod n = 73 mod 33 = 343 mod 33 = 13 After doing this the sequence (4) is converted to (5) c1, c2, c3, c4, c5, c6, c7 = 13, 9, 15, 8, 12, 21, 26 This sequence of numbers is the coded message which she sends to you. When you receive it you decode it by first decoding each number cj using (2). For example, 3.6.1 - 2 m1 = (c1)d mod n = 137 mod 33 = 62748517 mod 33 = 7 After doing this the sequence (5) is converted back to (2) which you then convert back to the text (3). Why does RSA work? The reason why RSA works relies on some elementary properties of mod and one not as elementary property of mod. Here is what happens with the first letter of the above message convert to number letter g code decode 3.6.1 - 3 convert back to letter