The RSA Cryptosystem
The RSA Cryptosystem (named for Rivest, Shamir, and Adleman) is a public key cryptosystem — that is, the keys used for encryption and decryption are different, and (in general) it is believed that it is difficult for an attacker to use knowledge of one number to produce the other.
Typically, RSA is used for one-way communication. The receiver produces a large number , and two numbers
(these numbers are chosen in a special way that I’ll soon describe). They publish the numbers
and
, but they keep the number
a secret. The sender uses
and
to encrypt their message; the receiver uses
and
to decrypt the number.
We’re going to take a look at how these numbers are chosen and how the encryption and decryption process works.
Some background
The RSA cryptosystem is based on some elementary facts about prime numbers. We’re going to review those facts right now, just to establish some context.
Definition 1 (Relatively prime). Let be positive integers. We say that
and
are relatively prime (sometimes also called coprime) if there does not exist an integer
where
divides both
and
.
Intuitively, two positive integers are relatively prime if they don’t have any of the same factors.
Definition 2 (Euler function). Let
be a positive integer. We define
to be the number of positive integers less than
that are relatively prime to
.
The function has the following property that motivates our interest in it:
Theorem 1 (Computing ). Let
be a positive integer. Factor
as
.
Then
.
Theorem 1 is extremely useful. If you don’t know how to factor , then computing
basically requires you to test very number less than
to see if it is relatively prime to
. If
is a
digit number (say, written in base 10), there are about
numbers you need to test. That grows pretty quickly! So quickly that it’s effectively impractical if
is a moderately big number.
The amazing power of Theorem 1, though, is that if you can factor , then you can compute
very efficiently. This asymmetry is at the heart of the RSA cryptosystem.
Theorem 2 (Euler’s Theorem). Let be relatively prime positive integers. Then
.
With that background out of the way, we are now ready to describe the RSA cryptosystem.
Choosing
.
The receiver begins by picking two prime numbers . These numbers will be treated as secret information; the receiver will never tell anyone what these numbers are. In practice, these are chosen to be very large; heuristically speaking, bigger primes will lead to better security. Then let
. This is how
is chosen. Note that by Theorem 1 the receiver can compute
rather easily, whereas anyone besides the receiver must compute
the hard way.
Now choose an integer with
where
and
are relatively prime. The number
and
are now published for the world to see.
The receiver now must produce a number that has the following relationship:
.
This is easy to do if one uses the Extended Euclidean Algorithm. The number is kept private, just like
and
.
Encrypting and decrypting messages
Now suppose someone wishes to send a secret number to the receiver. The encryption process is simple:
Let .
Now the sender transmits to the receiver.
To decrypt, the receiver computes
.
To see why this computation decrypts the message, simply apply Theorem 2. Since we chose such that
, we know that there exists some
such that
.
Then by Theorem 2,
.
Now, I feel as though I need to point out that I cheated a little bit. See, I wanted to apply Theorem 2, but in order to do so I must know that and
are relatively prime. I can’t actually guarantee that this will always be the case. However, since
is a factor of two primes, I’m only in trouble if
is divisible by one of these numbers. Since this is fairly uncommon, I don’t really worry about it too much. However, when it does happen, we are in a lot of trouble.
The security of the system is largely based on the idea that it is difficult to factor . Now, it turns out that it’s actually quite easy to determine if a given
and
share a factor; indeed, one needs only compute
, which can be done efficiently using the Euclidean Algorithm. If they do share a factor, then not only can the sender not use the RSA cryptosystem to send this message using this
, but in fact the sender has figured out the factorization of
. Once someone knows how to factor
, the security of the entire system is compromised.
So when this happens, rather than simply coming up with a different way to encrypt , it is probably a good idea to generate a whole new
to use for all future communications.
An example
Let’s compute an example of the RSA cryptosystem in action. Let and
. Then
, and
.
We now need to produce an that is relatively prime to
. I just picked
and got lucky in that it was already relatively prime to
. If I was unlucky, I would just pick
.
Finally, it’s time to compute . Using the Extended Euclidean Algorithm (well actually I cheated and just used a computer algebra system), I find that
.
Now suppose someone wants to send me the number . They compute and send to me
.
I receive this number, and immediately compute
,
which gives me the secret number.
The security of the RSA cryptosystem
If someone wants to attack the cryptosystem, the most obvious scheme would be to find a way to compute given
and
.
What are the challenges in doing this? The biggest one is in computing . You see, when the receiver produces the number
, they do so knowing how to factor
, and are therefore able to compute
efficiently using Theorem 1. However, when attacker wishes to compute
, they have no choice by to use the naive algorithm for computing
. If an attacker were to try to do this, the hope is that it would take so long that, by the time they had succeeded, the contents of the message have become moot.
However, if it were easy to factor the number , then the RSA cryptosystem would offer no real security. At the time of writing, there is not a general purpose factoring algorithm that is fast enough for this to be a reasonable attack. Still, there are many good factoring algorithms out there that give perfectly feasible attacks against implementations of the RSA cryptosystem that use relatively small prime numbers to produce
. In the articles that follow, we will look at some of these algorithms.




[...] cryptosystem. Thus, to kick the whole thing off, I’ve posted an account on the working of the RSA cryptosystem under my new special section on [...]
Factorization techniques « Integer Overflow
20 February, 2008 at 1:52 pm