RSA Encryption |
|
This page was prepared by Nathan Carter for MA 267 at Bentley College in the Fall of 2006. It is based upon a section in Goodaire and Parmenter's text. Page numbers will differ from the original textbook because our class is using a custom textbook which only contains part of the original. This page provides tools for use with the RSA Cryptography content on page 100 of your textbook. It also explains that content a bit more than the book does. Note that Wikipedia has an excellent entry on RSA encryption that explains things in even more detail than this page. Heck, Wikipedia has excellent entries on tons of stuff, and several key phrases below are links to Wikipedia articles. IntroductionRSA Cryptography allows an individual who wants to receive encoded messages to give other people a "public key" that encrypts the messages in such a way that the person who gave the key is the only one who knows how to decrypt them. The public key is a pair of numbers. Another pair of numbers makes up a corresponding "private key," which only the creator of the keys knows, and keeps secret. It is this private key that helps you decrypt numbers. Today all of this is handled by computers, and you can get software that will encrypt, decrypt, and securely sign messages for you. (See the Wikipedia article referenced above for more information.) But this page helps you work out an example yourself of how all this works, and explains the mathematics used as you go along. A running example is used at each step of the way. To create a public key
Your public key (the numbers you'll give to other people) are your r and s. Your "private key," which you must keep secret and is necessary to decode messages, is the pair of numbers p and q.
Encrypting a messageWe will only be allowed to encrypt numerical messages of length less than r. That's the first place where this page begins to help you. The input boxes and button below allows you to type in any text message and your public key, and it will encrypt the message for you. It just turns every character into a separate number and smooshes them together into a row. It also splits the number every so often (into what are called "blocks" of the message) to be sure each block is a number smaller than r and then follows the encryption scheme, that a block b of your message is encrypted to the remainder of bs divided by r. The legal characters to use in your message M are letters, numbers, spaces, and any of the following. . Note that your r and s values must have been created as described above. But the button above does not check to be sure the r and s you provide make sense; it just trusts you.
Decrypting a messageWhen decrypting, you not only have the public key r, s, but you also have your private key p, q. Recall (from pages 66-7 of your textbook) that whenever you have two relatively prime numbers, there is some linear combination of them that equals 1. We need to use this fact twice in preparing to decode an encrypted message E. Preparation (can be done in advance)First I'll need a pair of numbers a and b such that sa+(p-1)b=1. Your book shows you the extended Euclidean algorithm that will help you find a and b, but the input boxes and button below should make it go much faster. Once you've found a and b, you'll need to do the same thing again, finding c and d such that sc+(q-1)d=1. You can find a and b once up front, which is more efficient, back when you choose your p, q, and s, rather than once every time you decrypt. I just kept the material on this page in the same order it is in your textbook.
Why this mattersThis section does not involve any description of any work that needs to be done when decrypting, but it is important for me to take a moment to explain the purpose of the computations you just completed, and why they will be useful. Having the numbers a, b, c, and d, we are able to write the following two equations. They probably don't seem useful at first, but they will soon. M = M1 = Msa+(p-1)b = (Ms)a (Mp-1)b M = M1 = Msc+(q-1)d = (Ms)c (Mq-1)d Now whatever the original message M was that was encrypted, we know that Ms = E (mod r), and thus both Ms = E (mod p), and Ms = E (mod q), because both p and q divide r. This lets us simplify the above equations a little, mod p and q respectively. M = Ea (Mp-1)b (mod p) M = Ec (Mq-1)d (mod q) And in fact, we can simplify further. Fermat's Little Theorem (from page 91 of your textbook) says any number to the p-1 is congruent to 1 mod p for a prime p. So finally we have this. M = Ea (mod p) M = Ec (mod q)
The decryption itselfThe above two equations are just the type of problem the Chinese Remainder Theorem was built for. If we can provide values for Ea and Ec, the theorem shows us how to figure out the message M. The numbers Ea and Ec may be very large, and thus it is possible that whatever calculator you have at your disposal will not handle them. The following input boxes and button will compute smaller numbers that are congruent to the actual answers mod p and q, as needed.
Even if x and y are fairly large, the computations will be done in such a way that no calculator overflow occurs. It's interesting that y may sometimes be negative, which is okay because p is prime, and thus everything has a multiplicative inverse mod p. In fact, that inverse is the number F the extended Euclidean algorithm would give if we asked for values F and t such that FE + tp = 1.
Page 98 of your textbook gives an algorithm for applying the Chinese Remainder Theorem to situations just like the pair of equations above (once you've filled in Ea and Ec) to find a solution M < r as the example has done. The following input boxes and button will do it for you, if you enter the values correctly.
Note that the output in the blank above is a number, which will need to be converted back into text. The following table should help. Table for encoding/decoding single characters
|