What RSA Does
RSA gives you two keys:
- Public key: two numbers
- Private key: two numbers
To encrypt a message :
To decrypt ciphertext :
Raise to a power, take the remainder. That’s it.
Let’s Do It With Real Numbers
Say we have:
| Value | Number |
|---|---|
| 55 | |
| (public exponent) | 3 |
| (private exponent) | 27 |
Encrypt the message 2:
Ciphertext is 8.
Decrypt 8:
is a huge number. But when you divide by 55 and take the remainder, you get 2.
The original message comes back.
Where Do These Numbers Come From?
This is key generation. Here’s how we got 55, 3, and 27.
Step 1: Pick two prime numbers. Call them and .
Step 2: Multiply them to get .
This is public. Everyone can know it.
Step 3: Calculate .
For two primes, there’s a simple formula:
This is the secret. You can calculate because you know and . Someone who only knows would have to factor it first.
Step 4: Pick , the public exponent.
Choose any number that shares no common factors with .
Does 3 share any factors with 40? No. Good.
Step 5: Find , the private exponent.
We need where .
In other words: when we multiply by 3 and divide by 40, the remainder should be 1.
How do we find it? We search.
works because , and remainder .
The Keys
| Key | Components | Who knows it |
|---|---|---|
| Public | Everyone | |
| Private | Only you |
Why Does Decryption Work?
When you encrypt then decrypt, you’re doing:
For us:
Why Is It Secure?
An attacker knows and .
To find , they need .
To find , they need and .
To find and , they must factor .
For ? Trivial. .
For a 600-digit ? Nobody knows how to factor it efficiently.
RSA’s security rests on the difficulty of factoring large numbers.