Cryptography and RSA: Number Theory in Practice
RSA is a public-key cryptosystem whose security rests on the difficulty of factoring large integers. One-line statement: Encrypt with , decrypt with , where and is a product of two large primes. Where it applies: secure web traffic (TLS/HTTPS), digital signatures, email encryption, key exchange. Who/when: Ron Rivest, Adi Shamir, and Leonard Adleman, 1977 (publicly); Clifford Cocks, GCHQ, 1973 (classified).RSA is an asymmetric cipher in which each party holds a public key for encryption/verification and a private decryption exponent kept secret. Its correctness is a direct application of Euler's theorem and the Chinese Remainder Theorem from elementary number theory, while its security depends on the empirical hardness of the integer factorization problem. RSA matters because it solved the central problem of classical cryptography — how two parties who have never met can communicate securely over an open channel — and because it simultaneously provides authentication via digital signatures. The surprising fact: the very same number-theoretic operation that "obviously" cannot be undone (exponentiation modulo a composite) becomes trivially reversible if and only if you know how factors — so the entire edifice of modern internet security rests on the gap between multiplying two primes (easy) and recovering them (believed hard).
The Core Insight
Modular exponentiation by is a permutation of , and its inverse permutation is exponentiation by some . Computing from requires knowing , and computing requires knowing the factorization . Thus a trapdoor one-way function is born: easy forward (public ), easy backward with secret ( from the factorization), hard backward without it.
Formal Statement
RSA Key Generation, Encryption, Decryption
Let be distinct large primes and set the modulus . The Euler totient of is
Choose a public exponent with and . Define the private exponent as the modular inverse
The public key is ; the private key is (with also secret). For a message :
Symbols: — secret primes; — public modulus; — Euler totient (secret); — public exponent; — private exponent; — plaintext as integer; — ciphertext as integer.
RSA Correctness
With keys as above, for every ,
Hence decryption recovers the plaintext: .
Why It Holds / Derivation
Correctness of RSA via CRT and Fermat
We show and ; the Chinese Remainder Theorem then forces congruence mod .
Step 1 — Express . Since , write for some integer (from equation [2]). Step 2 — Work modulo . Two cases. Case (a): . Then , so Fermat's Little Theorem gives . ThereforeIn both cases .
Step 3 — Work modulo . By identical reasoning with in place of , . Step 4 — Recombine. We have and . Since are distinct primes, , i.e.This proves equation [5], so .
Note we used the full exponent argument and got correctness even when shares a factor with — a subtlety many proofs miss. The cleaner Euler-theorem version, , only holds when ; the CRT-by-cases proof above is strictly more general and handles the (negligibly rare) case .
Ron Rivest, Adi Shamir, Leonard Adleman | published 1977
At MIT, Rivest and Shamir repeatedly proposed candidate trapdoor functions which Adleman, the number theorist of the trio, repeatedly broke. The winning idea — modular exponentiation with the factorization as trapdoor — survived Adleman's attacks. Their paper, A Method for Obtaining Digital Signatures and Public-Key Cryptosystems (1978), defined modern asymmetric cryptography. Unknown to them, Clifford Cocks at the British GCHQ had described an essentially identical scheme in a 1973 classified memo, declassified only in 1997.
Building Intuition
Think of a public mailbox with a one-way slot. Anyone can drop a letter in (encrypt with the public key ), but only the owner with the physical key can open it (decrypt with ). The number-theoretic "slot" is the map . Because is coprime to , this map shuffles the residues into a permutation with no collisions — every ciphertext comes from exactly one plaintext. Undoing the shuffle means finding the inverse exponent , and the only known efficient route to passes through , which passes through factoring . Multiplying to build takes microseconds; reversing it for a 2048-bit would take the fastest known algorithms longer than the age of the universe.
The RSA trapdoor one-way function: easy forward and backward-with-key, hard backward-without-key
Worked Examples
Toy RSA with small primes
Given: , . Encrypt the message . Step 1 — Modulus. . Step 2 — Totient. (equation [1]). Step 3 — Public exponent. Choose . Check . ✓ Step 4 — Private exponent. Solve (equation [2]) via extended Euclid. One finds since . Step 5 — Encrypt (equation [3]): . Using square-and-multiply: . Step 6 — Decrypt (equation [4]): . ✓Computing the private key by hand
Given: public key , and the attacker has factored . Step 1 — Recover totient. . Step 2 — Extended Euclidean algorithm on : , , , . Back-substitute: . Step 3 — Read off the inverse. , so .Common Misconceptions
Textbook RSA is NOT secure as a real cipher. The raw map is deterministic: identical plaintexts always give identical ciphertexts (so it leaks equality), and it is malleable ( decrypts to ). It also leaks small-message structure. Real systems use padding schemes (OAEP for encryption, PSS for signatures) that inject randomness and structure. Never deploy "schoolbook" RSA. and are inverses mod , NOT mod . A frequent error is computing . The exponent arithmetic lives in the exponent group of order (or ), not in . Mixing the two moduli yields a that fails to decrypt.Why $e$ must be coprime to $\varphi(n)$
Suppose someone naively picks , so , , and chooses . Then , so does not exist — there is no with . The encryption map is not a bijection: it collapses distinct plaintexts to the same ciphertext (e.g. it is six-to-one on the unit group fibers), so decryption is impossible. The coprimality condition is exactly what makes a permutation.
Connections
RSA sits at the crossroads of pure number theory and applied security. Its correctness is pure Fermat's Little Theorem and the Chinese Remainder Theorem (also used for a 4× decryption speedup via CRT recombination of computations mod and mod ). The exponent inverse uses the Extended Euclidean Algorithm. Choosing and key generation lean on Euler's Totient Function and Primality Testing (Miller–Rabin). Security relates to the Integer Factorization Problem and to the broader Discrete Logarithm Problem underlying its cousin, Diffie–Hellman. The permutation structure is best understood in Group Theory via the unit group of order .
Real-World Applications
- TLS / HTTPS: historically RSA authenticated servers and encrypted the session key; modern TLS 1.3 uses RSA chiefly for signatures in certificates while key exchange moved to elliptic-curve Diffie–Hellman.
- X.509 digital certificates: Certificate Authorities (DigiCert, Let's Encrypt) sign certificates with RSA-PSS or RSA-PKCS#1 to bind identities to public keys.
- PGP / GPG email and file encryption: RSA encrypts the symmetric session key and signs messages.
- SSH: RSA host and user keys (
ssh-rsa, now often 3072–4096 bits) authenticate logins. - Code signing: Microsoft Authenticode, Apple, and Android app signing use RSA signatures to verify software provenance.
- Smart cards and EMV chip payment: RSA underlies offline data authentication in chip-and-PIN cards.
- Document/PDF signatures and e-government: national eID schemes and Adobe signatures rely on RSA-PSS.
Historical Development
- 1973 — Clifford Cocks (GCHQ) describes the RSA algorithm in a classified internal note; kept secret for 24 years.
- 1976 — Diffie & Hellman publish New Directions in Cryptography, introducing public-key cryptography and the trapdoor concept, but without a concrete encryption scheme.
- 1977 — Rivest, Shamir, and Adleman discover RSA at MIT; the famous "RSA-129" challenge cipher is posed in Martin Gardner's Scientific American column.
- 1978 — The RSA paper is published in Communications of the ACM.
- 1983 — MIT is granted U.S. Patent 4,405,829 on RSA (expired 2000).
- 1991 — RSA-PKCS#1 v1.5 standardized; later found vulnerable to Bleichenbacher's adaptive chosen-ciphertext attack (1998).
- 1994 — Peter Shor publishes a quantum algorithm factoring integers in polynomial time, theoretically breaking RSA on a future quantum computer.
- 1994 — RSA-129 (a 129-digit, ~426-bit challenge) is factored by a worldwide distributed effort, recovering the plaintext "THE MAGIC WORDS ARE SQUEAMISH OSSIFRAGE."
- 2020 — RSA-250 (829 bits) factored, the largest RSA challenge number broken to date, underscoring why ≥2048-bit keys are now mandated.