Public-Key Cryptography: RSA
RSA lets anyone lock a message with your public key, while only you can unlock it. Locking raises the message to a power mod n = pq, and unlocking raises it to a second power that undoes the first. Finding that second power needs p and q, and nobody knows how to factor a huge n quickly.
What the symbols mean
- Message
The plaintext, encoded as a number smaller than n.
- Ciphertext
The encrypted number that gets sent.
- Public exponent
Part of the public key.
- Private exponent
The secret key: the inverse of e.
- Modulus
The product of two secret primes p and q.
- First prime
Kept secret.
- Second prime
Kept secret.
Explanation
RSA is simply a way to let anyone send you a secret message without the two of you ever meeting to agree on a password. The name is just the initials of its inventors, Rivest, Shamir and Adleman, who published it in 1977. Think of it as handing out open padlocks: anyone can snap one shut on a box (that's the public key), but only you have the key that opens it. The formulas look like a lot, but there are only three pieces: (lock the message by raising it to the power ), (unlock it with a different power ) and (the rule that makes undo ). Everything else in this lesson is a tool you already built in this unit.
This is where the whole unit pays off. Primes, Euclid's algorithm, modular powers and inverses each play a part.
Key generation.
- Pick two large primes and and compute .
- Compute .
- Choose with , and let .
- Publish ; keep (and , ) secret.
Step 3 is the inverse from the last lesson, found with the extended Euclidean algorithm, and it exists because we chose to share no factor with .
Why decryption works. Remember how made big powers easy? Euler's theorem says the same kind of thing always happens: when . So exponents only matter mod . Since , we get . (It works for the other messages too, by the Chinese remainder theorem.) Euler's theorem generalizes Fermat's little theorem: for a prime not dividing .
Toy example. , , , , , (since ). The message encrypts to , and brings it back.
Security. Think about what an eavesdropper would need. Anyone can compute from if they know , and is easy given and . So RSA is only as strong as the difficulty of factoring . Multiplying two primes is quick, but undoing it is believed to be very hard: for 2048-bit moduli it's far beyond any known classical computer.
A common mistake. It's tempting to think the secret is the exponent , or the modulus , since those are what you compute with. It isn't: both are published for the whole world to see. The only secrets are and the primes and it came from.
See it
Worked examples
With and , choose . Find , and , then encrypt .
- 1
and .
Practice
Type your answer and check it. Solve them all to complete the lesson.
With and , what is ?
Encrypt with and .
Find with .
Why is RSA hard to break?
Alice's public key is . Bob sends her the message . What ciphertext does he send?
For Alice's key, and . Find her private exponent .
The hardest one here. Get it, and you've got this lesson.
Eve intercepts the ciphertext , sent with the public key . The modulus is small enough to factor. Recover the message .
Where it's used
Browsers use RSA or its relatives to set up secure connections and to check that software updates really come from their publishers.