RSA & Public-Key
Cryptography
Discover how two different keys enable secure communication: the mathematics of modular exponentiation, prime factoring, and the RSA algorithm.
What Is Cryptography?
Cryptography is the science of encoding messages so that only authorized parties can read them. Every time you visit a website with HTTPS, send a text message, or make an online payment, cryptography protects your data.
Two Kinds of Keys
Why RSA Matters
RSA (Rivest, Shamir, Adleman, 1977) was one of the first practical public-key systems and is still widely used today. Its security rests on a single hard problem:
Foundation: Modular Arithmetic
RSA relies on modular arithmetic: computing remainders. We write \( a \equiv b \pmod{n} \) to mean \( n \) divides \( (a - b) \).
Euler's Totient Function \( \phi(n) \)
\( \phi(n) \) counts the integers from 1 to \( n \) that are coprime to \( n \) (share no common factor except 1). This function is the mathematical engine of RSA.
The RSA Algorithm
Why RSA Works
The correctness of RSA follows from Euler's Theorem. Starting from ciphertext \( C = M^e \pmod{n} \):
Public vs Private Key
| Public Key \((e, n)\) | Private Key \((d, n)\) | |
|---|---|---|
| Visibility | Shared with everyone | Known only to owner |
| Used for | Encrypting messages | Decrypting messages |
| Also used for | Verifying signatures | Creating signatures |
| If compromised | No harm: it is already public | All security is lost |
| Derivation | Choose freely (\(e = 65537\) common) | Computed from \( e, \phi(n) \) |
How to Apply RSA
Example 1: Tiny RSA
Let's build RSA with the smallest primes possible and encrypt the message \( M = 4 \).
Example 1: Decryption
We received ciphertext \( C = 9 \) and hold private key \( (d, n) = (27, 55) \). Let's recover the original message.
Example 2: Larger Primes
Now with \( p = 7, \; q = 13 \), encrypt \( M = 10 \).
The Trapdoor Function
Common Mistakes
RSA Summary Table
| Component | Symbol | Role |
|---|---|---|
| Two large primes | \( p, q \) | Secret: generate keys, then discard |
| Modulus | \( n = pq \) | Part of both keys |
| Totient | \( \phi(n) = (p-1)(q-1) \) | Secret: used to compute \( d \) |
| Public exponent | \( e \) | Encrypt & verify signatures |
| Private exponent | \( d \) | Decrypt & create signatures |
| Encryption | \( C = M^e \pmod n \) | Anyone can do this |
| Decryption | \( M = C^d \pmod n \) | Only key owner can do this |
Question 1 of 5
In RSA, the public key consists of which pair of values?
Question 2 of 5
If \( p = 3 \) and \( q = 11 \), what is \( \phi(n) \)?
Question 3 of 5
RSA's security relies on the difficulty of which mathematical problem?
Question 4 of 5
Given \( n = 55 \), \( e = 3 \), and plaintext \( M = 2 \), what is the ciphertext \( C \)?
Question 5 of 5
What relationship must \( e \) and \( d \) satisfy for RSA to work correctly?