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).
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
Let be distinct large primes and set the modulus . The Euler totient of is
Derivation hint: is multiplicative for coprime factors, and for prime ; alternatively count integers in not divisible by or via inclusion–exclusion. Choose a public exponent with and . Define the private exponent as the modular inverse
Derivation hint: exists and is unique mod precisely because ; compute it with the extended Euclidean algorithm. The public key is ; the private key is (with also secret). For a message :
Derivation hint: is reduced modulo via fast modular exponentiation (square-and-multiply).
Derivation hint: substitute to get , then apply the correctness theorem below. Symbols: — secret primes; — public modulus; — Euler totient (secret); — public exponent; — private exponent; — plaintext as integer; — ciphertext as integer.
With keys as above, for every ,
Derivation hint: prove separately mod and mod using Fermat's little theorem, then recombine by the Chinese Remainder Theorem. Hence decryption recovers the plaintext: .
Why It Holds / Derivation
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 . Therefore
Derivation hint: factor the exponent so that a multiple of appears, then apply . *Case (b): .* Then and likewise , so trivially. In 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.
Derivation hint: two distinct primes both dividing an integer means their product divides it (coprimality + CRT). 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 .
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.
Worked Examples
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]): . ✓
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 .
Moral: the instant is factored, falls out of one Euclidean computation. Security unfactorability.
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.
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
Historical Development
Subtleties & Limits
Is RSA equivalent to factoring? It is not proven that breaking RSA (recovering from without ) is as hard as factoring . Computing or is known to be equivalent to factoring, but the RSA problem — extracting -th roots mod — might conceivably be easier than full factorization; no such shortcut is known, yet none is ruled out. Meanwhile, Shor's algorithm breaks RSA in polynomial time on a large fault-tolerant quantum computer, making RSA vulnerable in a post-quantum world and driving the migration to lattice-based schemes (e.g. NIST's CRYSTALS-Kyber/Dilithium). Practical sub-exponential classical factoring (the General Number Field Sieve) sets the key-size goalposts: 2048-bit keys are currently safe classically, but their long-term security is an empirical, not a proven, guarantee.
See Also
Chinese Remainder Theorem · Integer Factorization Problem · Discrete Logarithm Problem · Group Theory · Primality Testing · Diffie–Hellman Key Exchange · Elliptic Curve Cryptography · Digital Signatures