RSA Encryption
In A Mathematician's Apology, G. H. Hardy wrote:
[Number theorists] may be justified in rejoicing that there is one science, at any rate, and that their own, whose very remoteness from ordinary human activities should keep it gentle and clean.
How wrong he was.
Number theory is the core of modern cryptography today, which is central to all kinds of online activity.
RSA, first proposed by Ronald Rivest, Adi Shamir, and Leonard Adleman in 1977, is a cryptosystem that also—you guessed it—relies on number theory.
So, we have two players: a sender and a receiver.
The receiver has two keys: public and private. The sender encrypts their message with the public key of the receiver, which is obviously public, and the receiver can decrypt the message using their private key which is known only to the receiver. The beauty of it is that the sender and the receiver don't need to agree on a key beforehand.
Let's see how the receiver can generate public and private keys.
|
First, generate two primes, and . ( and tend to be, you know, As Random As Possible and Many Digits Long). |
Multiply and to get . In other words, let . |
Then, find an integer such that , that is, is relatively prime to . * |
The pair is the public key which can be distributed. |
Because is relatively prime to , it has an inverse () in , let's call it . ** |
is the private key that the receiver keeps hidden. |
* Remember Euler's totient function? ( for primes .)
** Remember that is the set of numbers in that are relatively prime to .
If you knew what and are, it'd be easy to figure out what the private key is. Well, the thing with one-way functions is that they are easy to compute but hard to invert. So, even if it's easy to compute the product of and to get , it's hard to factor to get and .
What about the sender?
First, the message that they are going to send to the receiver has to be in the range , which means it can be represented by a Many Digits Long number.
Because the sender knows the receiver's public key, they need to raise the message to in (has to be ) to get the encoded message :
Then, how does the receiver decode ?
They just need to raise to their private key in (again, ) to get the decoded message: