The RSA algorithm is one of the most used asymmetric encryption algorithm. Ever since its public release in 1977, its become the one of the most prominent systems for encryption and digital signature. But it’s creation is the byproduct of centuries of mathematical discoveries in Number Theory whose mathematical foundations continue to influence modern cryptography. Let me guide you through its rich history and make you excited about it!

This article will contain math notation. If you get lost, you can reference this list of notation towards the end of the article.

The Number Theoretic History of RSA

When it comes to discoveries or patterns in number theory, more likely then not, Fermat noticed it first. He noticed the following phenomenon back in 1640:

Fermat's Little Theorem (1640)

  • Let p be a prime and a be an integer such that , then

One powerful consequence of Fermat’s little theorem is it’s ability to examine polynomials form . These polynomials are extremely important for cryptography. It’s the basis of many encryption and decryption schemes. We can actually build a simple one using Fermat’s Little Theorem in the following way:

Suppose we choose a prime , and our message . We can generate public key and private key if we satisfy the following equation:

  • We want to solve this particular equation as finding the keys would be non-trivial! It simply requires to first choose any number that is co-prime to p-1, and then running the Euclidean algorithm to solve for !

To get our encrypted message we will just do the following:

And why does this work? Well its just simple modular arithmetic!

The problem

If two parties wanted to send encrypted messages to each other, they would need to send over the public key and the prime number used in order to decrypt it. Using both the public and the prime number, an adversary could easily find compute private key by running the extended Euclidean Algorithm!

You could even decrypt it without the public key! Given the prime, there are p-1 options you could test to try to brute force the message. In order to get a better system to encrypt and decrypt messages, we need an algorithm that is harder to generate the private key and brute force.

Adding a new level of complexity, Integer Factorization

Since part of the process is to first, find an agreed upon pair of keys, why not make the modulos the harder part to break? There lies the Integer factorization problem! When given an integer, we already have quick methods of multiplying two integers, but we currently do not have an easy way to find the prime factors given any integer. So instead of making out modulus a single prime, we can make it the product of two very large primes! (I won’t go into detail as to why, but just know that its important. The larger the primes are, the longer it takes for a computer to figure out its prime factors)

Euler to the rescue

The problem with Fermat’s Little Theorem is its reliance of a prime number. Luckily, Euler noticed the following phenomenon!

Eulers Theorem (1760)

  • If and , then

Now we can reconstruct our encryption and decryption primitives in the following way:

Now you may be wondering: Wouldn’t the attacker be able to easily find the private key? NO! You have to remember, is locked behind the difficulty of finding the primes of ! Current integers used for modern day RSA are about 308 decimal digits long. This computation using modern computers would require computational time that far exceeds the age of the universe!

The Chinese Remainder Theorem!

The most beautiful part of RSA is seeing the Chinese Remainder Theorem working behind the scenes for the public and private key generation. It all starts with out ability to break apart the modulus.

Modulo Factorization

Let be the factorization of N into pair-wise co-prime factors. Then the congruence is equivalent to

We break apart such that we can rewrite into the following system of equations:

And when we have a system as such, we can now use the Chinese remainder theorem!

Chinese Remainder Theorem (3rd-5th C.E., proved by Gauss 1801)

Let be positive integers such that for . Then the linear congruence’s:

has a simultaneous solution, which is unique modulo the integer .

Can you make your own primitive?

As you can see, RSA is the final product of interlocking many different mechanisms in number theory. From the Chinese remainder to Euler to even Gauss, it is one of the most beautiful examples of how centuries of mathematical curiosity lead to one of the most used algorithms in our modern age.

Quick Notation Reference

VariableReference
Large Primes Numbers
Message we want to encrypt
Encrypted message we will send or decrypt
Public Key
Private Key
modulus ()
Euler-Totient Function

Back Links

Fermat’s Little Theorem Euler’s Theorem Chinese Remainder Theorem Modulo Factorization Theorem