RSA Cryptosystem

How can two strangers, with no shared secret and no private meeting, exchange a message that no eavesdropper can read? For most of history the answer was that they could not. This was true unless a secure channel already existed to carry a key. The RSA cryptosystem was published in 1978 by Ronald Rivest, Adi Shamir, and Leonard Adleman. It was the first practical answer to this puzzle. It converted a question of secure communication into a question of number theory: is it hard to factor a large integer that is a product of two primes? The idea is strikingly simple once seen. Choose two large primes, multiply them, and use the Euler totient function of that product. This builds a pair of exponents — one public, one private. These exponents are multiplicative inverses of each other modulo the totient. Encryption raises a message to the public exponent. Decryption raises the result to the private exponent. That decryption recovers the original message is not an accident of arithmetic. It is a direct consequence of the Euler–Fermat theorem. This is the same theorem that governs the order of units modulo nn. The significance of RSA goes beyond its cleverness. It demonstrated something important about public-key cryptography. In such systems, the encryption method can be published openly while decryption remains secret. This was not merely a theoretical fantasy sketched by Diffie and Hellman. It was an implementable system resting on classical number theory: primality, the Euler Totient Function, and modular arithmetic. It converted number theorists' curiosity about factoring into a matter of practical, economic, and even geopolitical importance. The security of banking, web browsers, and digital signatures now depends on the presumed difficulty of factoring large semiprimes. This article builds RSA from the ground up. We define key generation, encryption, and decryption precisely. We prove correctness rigorously using Euler's theorem. This includes handling the subtlety of messages not coprime to the modulus via the Chinese Remainder Theorem. We work through two fully numerical examples. We also examine exactly which hypotheses are load-bearing. Finally, we consider which failures of them break the scheme.

Key takeaways
  • RSA encodes messages as integers modulo n=pqn = pq, a product of two distinct large primes.
  • The public exponent ee and private exponent dd satisfy ed≡1(modφ(n))ed \equiv 1 \pmod{\varphi(n)}.
  • Encryption is c≡me(modn)c \equiv m^e \pmod n; decryption is m≡cd(modn)m \equiv c^d \pmod n.
  • Correctness follows from Euler's theorem, extended to all residues (including non-units) via CRT.
  • Security is believed to rest on the hardness of factoring nn, not proven equivalent to it.
  • Key idea: exponentiation mod nn is easy to invert only if you know φ(n)\varphi(n), which requires knowing the factorization of nn.

Where this lives today

RSA underlies much of practical public-key cryptography: TLS/SSL handshakes that secure web traffic, PGP and S/MIME email encryption, code-signing certificates, and SSH key authentication all use RSA or its close descendants for key exchange and digital signatures. The correctness proof given here — Euler's theorem plus CRT — is also exactly the identity exploited in fast RSA implementations: decryption is done separately modulo pp and modulo qq (each with a much smaller exponent, via Fermat's little theorem) and then recombined by CRT, giving roughly a fourfold speedup over direct exponentiation mod nn. Beyond cryptography, RSA is a standard teaching vehicle in computational number theory courses for illustrating fast modular exponentiation, the extended Euclidean algorithm, and primality testing (needed to generate pp and qq in the first place), and it motivated decades of research into integer factorization algorithms (Pollard's rho, the quadratic sieve, the number field sieve) precisely because breaking RSA via factoring became a concrete, well-funded research target.

Ask the tutor: How does the CRT-based decryption speedup used in real implementations follow from the same correctness proof given here?

DefinitionRSA key generation, encryption, decryption

Key generation. Choose two distinct odd primes p≠qp \neq q and set

n=pq,φ(n)=(p−1)(q−1).n = pq, \qquad \varphi(n) = (p-1)(q-1).

Choose an integer ee with 1<e<φ(n)1 < e < \varphi(n) such that

gcd⁡(e,φ(n))=1.\gcd(e, \varphi(n)) = 1.

Compute the unique integer dd with 1<d<φ(n)1 < d < \varphi(n) satisfying

ed≡1(modφ(n)),ed \equiv 1 \pmod{\varphi(n)},

which exists and is unique modulo φ(n)\varphi(n) because ee is invertible in (Z/φ(n)Z)×(\mathbb{Z}/\varphi(n)\mathbb{Z})^\times. The pair (n,e)(n, e) is the public key; the pair (n,d)(n, d) (together with p,q,φ(n)p, q, \varphi(n), kept secret) is the private key.

Encryption. A message is encoded as an integer mm with 0≤m<n0 \le m < n. The ciphertext is

c≡me(modn),0≤c<n.c \equiv m^e \pmod n, \qquad 0 \le c < n.

Decryption. Given ciphertext cc, recover

m′≡cd(modn),0≤m′<n.m' \equiv c^d \pmod n, \qquad 0 \le m' < n.

The scheme is correct if m′=mm' = m for every valid message mm with 0≤m<n0 \le m < n.

Intuition

Think of nn as a padlock that anyone can snap shut but that only the key-holder can open. Snapping it shut corresponds to raising mm to the power ee modulo nn — an operation any onlooker can perform because nn and ee are public. Opening it corresponds to raising to the power dd. The reason this asymmetry is possible is that ee and dd are inverses not modulo nn, but modulo the hidden number φ(n)\varphi(n), and computing φ(n)=(p−1)(q−1)\varphi(n) = (p-1)(q-1) requires knowing pp and qq — which is exactly what factoring nn would reveal, and factoring large numbers is (believed) computationally hard. A helpful picture is the "clock inside a clock." The exponent arithmetic ed≡1(modφ(n))ed \equiv 1 \pmod{\varphi(n)} happens on a small hidden clock of size φ(n)\varphi(n); but the raw computation me  nm^e \bmod n happens on the big public clock of size nn. Euler's theorem is the gear that connects the two clocks: raising a unit mm to a multiple of φ(n)\varphi(n) brings you back to 11 on the big clock, precisely because the order of any unit divides φ(n)\varphi(n), the size of the small clock.

Figure
Two nested moduli: exponents live mod φ(n), messages live mod n
mod n = pq (messages, ciphertexts) m c = m^e mod n mod φ(n) (exponents e, d) e d, ed ≡ 1 Euler's theorem links the two clocks: m^(k·φ(n)+1) ≡ m (mod n)

The other subtlety worth picturing is that Euler's theorem, in its basic form, only speaks about units — residues mm coprime to nn. Since n=pqn = pq, the only non-units modulo nn in the range [0,n−1][0, n-1] are the multiples of pp or of qq, a rare and controllable set. Correctness for these exceptional messages needs a separate short argument, supplied by the Chinese Remainder Theorem, and this is where a fully rigorous proof must do a bit more work than "just cite Euler."

TheoremRSA correctness

Let p≠qp \neq q be distinct primes, n=pqn = pq, and φ(n)=(p−1)(q−1)\varphi(n) = (p-1)(q-1). Let e,de, d be positive integers with

ed≡1(modφ(n)).ed \equiv 1 \pmod{\varphi(n)}.

Then for every integer mm with 0≤m<n0 \le m < n,

(me)d≡m(modn).(m^e)^d \equiv m \pmod n.

In particular, RSA encryption followed by RSA decryption recovers the original message exactly, for every message in {0,1,…,n−1}\{0, 1, \dots, n-1\}, not merely for those coprime to nn.

LemmaEuler's theorem, restated

If gcd⁡(a,n)=1\gcd(a, n) = 1 then aφ(n)≡1(modn)a^{\varphi(n)} \equiv 1 \pmod n.

Proofof the Theorem

Setup. Since ed≡1(modφ(n))ed \equiv 1 \pmod{\varphi(n)}, there is an integer k≥0k \ge 0 such that

ed=1+kφ(n).ed = 1 + k\varphi(n).

We must show med≡m(modn)m^{ed} \equiv m \pmod n for all m∈{0,1,…,n−1}m \in \{0, 1, \dots, n-1\}. Because n=pqn = pq with p,qp, q distinct primes, by the Chinese Remainder Theorem the map

Z/nZ  ⟶  Z/pZ×Z/qZ,x  n  ↦  (x  p,  x  q)\mathbb{Z}/n\mathbb{Z} \;\longrightarrow\; \mathbb{Z}/p\mathbb{Z} \times \mathbb{Z}/q\mathbb{Z}, \qquad x \bmod n \;\mapsto\; (x \bmod p,\; x \bmod q)

is a ring isomorphism. Consequently med≡m(modn)m^{ed} \equiv m \pmod n holds if and only if both

med≡m(modp)andmed≡m(modq)m^{ed} \equiv m \pmod p \qquad \text{and} \qquad m^{ed} \equiv m \pmod q

hold. We prove the first congruence; the second is identical with pp and qq interchanged.

Case 1: p∣mp \mid m. Then m≡0(modp)m \equiv 0 \pmod p, so med≡0≡m(modp)m^{ed} \equiv 0 \equiv m \pmod p trivially (since ed≥1ed \ge 1).

Case 2: p∤mp \nmid m. Then gcd⁡(m,p)=1\gcd(m, p) = 1. By Fermat's little theorem (the prime case of Euler's theorem),

mp−1≡1(modp).m^{p-1} \equiv 1 \pmod p.

Since (p−1)∣φ(n)=(p−1)(q−1)(p-1) \mid \varphi(n) = (p-1)(q-1), write φ(n)=(p−1)⋅(q−1)\varphi(n) = (p-1)\cdot(q-1); then

mkφ(n)=(mp−1)k(q−1)≡1k(q−1)=1(modp).m^{k\varphi(n)} = \left(m^{p-1}\right)^{k(q-1)} \equiv 1^{k(q-1)} = 1 \pmod p.

Therefore

med=m1+kφ(n)=m⋅mkφ(n)≡m⋅1=m(modp).m^{ed} = m^{1 + k\varphi(n)} = m \cdot m^{k\varphi(n)} \equiv m \cdot 1 = m \pmod p.

In both cases med≡m(modp)m^{ed} \equiv m \pmod p. By the identical argument with qq in place of pp (using (q−1)∣φ(n)(q-1) \mid \varphi(n)), we get med≡m(modq)m^{ed} \equiv m \pmod q.

Recombination. Since pp and qq are distinct primes, gcd⁡(p,q)=1\gcd(p,q) = 1, and med−mm^{ed} - m is divisible by both pp and qq, hence by pq=npq = n. Thus

med≡m(modn).m^{ed} \equiv m \pmod n.

Since decryption computes cd  nc^d \bmod n with c≡me(modn)c \equiv m^e \pmod n, we have cd≡med≡m(modn)c^d \equiv m^{ed} \equiv m \pmod n, and since both the recovered value and mm lie in [0,n−1][0, n-1], the recovered value equals mm exactly. ■\blacksquare

∎

Remark on proof technique. The proof uses reduction to prime moduli via CRT, a standard device precisely because Euler's theorem, in its elementary form, is a clean statement only about units; passing to Z/pZ\mathbb{Z}/p\mathbb{Z} and Z/qZ\mathbb{Z}/q\mathbb{Z} turns the multiples of pp or qq into the trivial zero case, so no separate machinery (Carmichael function, group actions) is needed — only Fermat's little theorem, applied twice, and the CRT isomorphism.

CorollaryEncryption and decryption are mutually inverse bijections

The maps E:m↦me  nE: m \mapsto m^e \bmod n and D:c↦cd  nD: c \mapsto c^d \bmod n are both bijections of {0,1,…,n−1}\{0, 1, \dots, n-1\} to itself, and D∘E=E∘D=idD \circ E = E \circ D = \mathrm{id}.

Proof

By the theorem, D(E(m))=mD(E(m)) = m for all m∈{0,…,n−1}m \in \{0,\dots,n-1\}, so D∘E=idD \circ E = \mathrm{id} on a finite set of size nn; a function from a finite set to itself with a left inverse that is itself a function on the same finite set must be a bijection (injectivity of EE follows since D∘E=idD\circ E = \mathrm{id} forces EE injective, and an injective self-map of a finite set is surjective, hence bijective). The same argument with e,de, d swapped — noting de≡1(modφ(n))de \equiv 1 \pmod{\varphi(n)} as well, since multiplication is commutative — gives E∘D=idE \circ D = \mathrm{id} and bijectivity of DD. ■\blacksquare

∎

Worked examples

Example 1: full key generation and encryption/decryption with asymmetric numbers. Let p=61p = 61, q=53q = 53 (deliberately unequal, of different bit-lengths in spirit). Then

n=pq=61×53=3233,φ(n)=60×52=3120.n = pq = 61 \times 53 = 3233, \qquad \varphi(n) = 60 \times 52 = 3120.

Choose e=17e = 17. Check gcd⁡(17,3120)=1\gcd(17, 3120) = 1: since 3120=24⋅3⋅5⋅133120 = 2^4 \cdot 3 \cdot 5 \cdot 13 and 1717 is prime and shares no factor with these, indeed gcd⁡(17,3120)=1\gcd(17,3120)=1. Find dd with 17d≡1(mod3120)17d \equiv 1 \pmod{3120} via the extended Euclidean algorithm:

3120=183×17+9,17=1×9+8,9=1×8+1,8=8×1.3120 = 183 \times 17 + 9, \quad 17 = 1\times 9 + 8, \quad 9 = 1\times 8+1, \quad 8 = 8\times 1.

Back-substitute:

1=9−1×8=9−(17−9)=2×9−17=2(3120−183×17)−17=2×3120−367×17.1 = 9 - 1\times 8 = 9 - (17-9) = 2\times 9 - 17 = 2(3120 - 183\times 17) - 17 = 2\times 3120 - 367\times 17.

So −367×17≡1(mod3120)-367 \times 17 \equiv 1 \pmod{3120}, i.e. d≡−367≡3120−367=2753(mod3120)d \equiv -367 \equiv 3120 - 367 = 2753 \pmod{3120}. Check: 17×2753=4680117 \times 2753 = 46801. Divide: 46801/3120=15.0003…46801 / 3120 = 15.0003\ldots, and 15×3120=4680015 \times 3120 = 46800, so 17×2753=46800+1=4680117 \times 2753 = 46800 + 1 = 46801, confirming 17×2753≡1(mod3120)17 \times 2753 \equiv 1 \pmod{3120}. So d=2753d = 2753. Public key: (n,e)=(3233,17)(n,e) = (3233, 17). Private key: (n,d)=(3233,2753)(n,d) = (3233, 2753).

Encrypt m=65m = 65 (an asymmetric, non-round choice). Compute c=6517  3233c = 65^{17} \bmod 3233 by repeated squaring:

651≡65,652=4225≡4225−3233=992,654≡9922  3233.65^1 \equiv 65,\quad 65^2 = 4225 \equiv 4225 - 3233 = 992,\quad 65^4 \equiv 992^2 \bmod 3233.

9922=984064992^2 = 984064. Divide: 984064/3233≈304.4984064 / 3233 \approx 304.4, and 304×3233=982832304 \times 3233 = 982832, remainder 984064−982832=1232984064 - 982832 = 1232. So 654≡123265^4 \equiv 1232.

658≡12322  3233.65^8 \equiv 1232^2 \bmod 3233.

12322=15178241232^2 = 1517824. 469×3233=1516277469 \times 3233 = 1516277; remainder 1517824−1516277=15471517824 - 1516277 = 1547. So 658≡154765^8 \equiv 1547.

6516≡15472  3233.65^{16} \equiv 1547^2 \bmod 3233.

15472=23932091547^2 = 2393209. 740×3233=2392420740\times 3233 = 2392420; remainder 2393209−2392420=7892393209-2392420 = 789. So 6516≡78965^{16}\equiv 789. Now 17=16+117 = 16 + 1, so

6517≡6516×651≡789×65  3233.65^{17} \equiv 65^{16}\times 65^1 \equiv 789 \times 65 \bmod 3233.

789×65=51285789\times 65 = 51285. Divide: 15×3233=4849515\times 3233 = 48495; remainder 51285−48495=279051285 - 48495 = 2790. So c=2790c = 2790.

Decrypt c=2790c=2790 using d=2753d = 2753: we must verify 27902753≡65(mod3233)2790^{2753} \equiv 65 \pmod{3233}. Rather than repeat a 2753-step exponentiation by hand in full, we verify correctness structurally, as the theorem guarantees, and spot-check consistency using the multiplicative structure: since 6565 and 3233=61×533233 = 61\times 53 share no common factor (65=5×1365 = 5\times 13, coprime to 6161 and 5353), Euler's theorem applies directly to m=65m=65, and the theorem proved above guarantees

27902753≡6517⋅2753≡651+15×3120≡65(mod3233),2790^{2753} \equiv 65^{17\cdot 2753} \equiv 65^{1 + 15\times 3120} \equiv 65 \pmod{3233},

using 17×2753=46801=1+15×312017\times 2753 = 46801 = 1 + 15\times 3120 exactly as computed above. This is the content of the correctness theorem applied to this specific numerical instance; the reader can confirm it by continuing the square-and-multiply decryption to the same value 6565.

Example 2: a message that is not coprime to nn (testing the CRT case of the proof). Keep n=3233=61×53n = 3233 = 61\times 53, e=17e=17, d=2753d=2753 from Example 1, but now encrypt

m=61×4=244,m = 61 \times 4 = 244,

which shares the factor 61=p61 = p with nn, so gcd⁡(m,n)=61≠1\gcd(m,n) = 61 \ne 1 — exactly the case Euler's basic theorem does not directly cover, and which our proof handled via the p∣mp \mid m case. Compute c≡24417(mod3233)c \equiv 244^{17} \pmod{3233}. First reduce modulo p=61p=61 and q=53q=53 separately (legitimate by CRT, and a useful shortcut mirroring the proof): Modulo 6161: 244=4×61+0244 = 4\times 61 + 0, so 244≡0(mod61)244 \equiv 0 \pmod{61}, hence 24417≡017=0(mod61)244^{17}\equiv 0^{17} = 0\pmod{61}. Modulo 5353: 244=4×53+32244 = 4\times 53 + 32, so 244≡32(mod53)244\equiv 32\pmod{53}. Compute 3217  5332^{17}\bmod 53 by Fermat: since gcd⁡(32,53)=1\gcd(32,53)=1 and 5353 prime, 3252≡1(mod53)32^{52}\equiv1\pmod{53}, but we need 321732^{17} directly. Square-and-multiply:

322=1024≡1024−19×53=1024−1007=17(mod53).32^2 = 1024 \equiv 1024 - 19\times53 = 1024-1007=17\pmod{53}.
324≡172=289≡289−5×53=289−265=24(mod53).32^4 \equiv 17^2 = 289 \equiv 289 - 5\times53 = 289-265=24\pmod{53}.
328≡242=576≡576−10×53=576−530=46(mod53).32^8 \equiv 24^2 = 576 \equiv 576-10\times53=576-530=46\pmod{53}.
3216≡462=2116≡2116−39×53=2116−2067=49(mod53).32^{16}\equiv 46^2=2116\equiv 2116-39\times53=2116-2067=49\pmod{53}.
3217≡3216×32≡49×32=1568≡1568−29×53=1568−1537=31(mod53).32^{17}\equiv 32^{16}\times32 \equiv 49\times32=1568\equiv 1568-29\times53=1568-1537=31\pmod{53}.

So c≡0(mod61)c \equiv 0 \pmod{61} and c≡31(mod53)c \equiv 31 \pmod{53}. Solve by CRT: we want c=61kc = 61k with 61k≡31(mod53)61k \equiv 31 \pmod{53}. Since 61≡8(mod53)61\equiv 8\pmod{53}, solve 8k≡31(mod53)8k\equiv31\pmod{53}. The inverse of 88 mod 5353: 8×20=160=3×53+1=159+18\times 20 = 160 = 3\times53+1=159+1, so 8−1≡20(mod53)8^{-1}\equiv20\pmod{53}. Then k≡20×31=620≡620−11×53=620−583=37(mod53)k \equiv 20\times31 = 620 \equiv 620-11\times53=620-583=37\pmod{53}. So k=37k=37 gives c=61×37=2257c = 61\times37=2257, and we check 2257<32332257 < 3233. So c=2257c=2257.

Decryption recovers m=244m=244: by the theorem (Case 1 of the proof, p∣mp\mid m), cd≡0(mod61)c^d \equiv 0 \pmod{61} automatically matches m≡0(mod61)m\equiv0\pmod{61}; and modulo 5353, since gcd⁡(32,53)=1\gcd(32,53)=1, Fermat's theorem applies to give 3217×2753≡321+15×3120≡32(mod53)32^{17\times2753}\equiv 32^{1+15\times3120}\equiv 32\pmod{53} exactly as in the generic argument, so cd≡244(modn)c^d \equiv 244 \pmod n by CRT recombination — confirming that even though mm shared a factor with nn, decryption still exactly recovers mm, as guaranteed by the full (not restricted-to-units) correctness theorem.

Counterexampledropping "p ≠ q" breaks correctness

Suppose we relax the hypothesis p≠qp \neq q and allow p=qp = q, say p=q=61p = q = 61, so n=p2=3721n = p^2 = 3721. First, the formula φ(n)=(p−1)(q−1)\varphi(n) = (p-1)(q-1) is simply wrong here: the correct Euler totient of n=p2n=p^2 is φ(p2)=p2−p=p(p−1)=61×60=3660\varphi(p^2) = p^2 - p = p(p-1) = 61\times60=3660, whereas (p−1)(q−1)=60×60=3600≠3660(p-1)(q-1) = 60\times60=3600 \ne 3660. So even key generation is already miscalibrated if one blindly reuses the two-distinct-primes formula. But the deeper failure is in the proof, not just the formula: the Chinese Remainder Theorem step required pp and qq coprime as distinct primes to get the isomorphism Z/nZ≅Z/pZ×Z/qZ\mathbb{Z}/n\mathbb{Z}\cong \mathbb{Z}/p\mathbb{Z}\times\mathbb{Z}/q\mathbb{Z}. If p=qp=q, then n=p2n=p^2 is not a product of coprime factors, this isomorphism fails, and the "recombination via gcd⁡(p,q)=1\gcd(p,q)=1" step of the proof has no content. Concretely, take m=p=61m = p = 61 itself, with n=612=3721n = 61^2 = 3721. Then mm is a zero divisor mod nn but m2≡0(modn)m^2 \equiv 0 \pmod{n} is false (612=3721≡061^2=3721\equiv0, actually true) — but consider instead m=2p=122m = 2p = 122: then m2=14884=4×3721=4n≡0(modn)m^2 = 14884 = 4\times3721 = 4n \equiv 0\pmod n, so already m2≡0m^2\equiv 0, and any exponent ed≥2ed\ge 2 collapses mm to 00, yet m=122≠0m=122\ne0. So decryption of such an mm can never recover mm correctly for any choice of (e,d)(e,d) once ed≥2ed \ge 2, since med≡0≢m(modn)m^{ed}\equiv 0 \not\equiv m \pmod n. This shows the hypothesis p≠qp\ne q (equivalently, nn squarefree with exactly two prime factors) is not a cosmetic convenience — it is essential to both the totient formula and the CRT step that makes the correctness proof go through.

Scope, edge cases & common traps

SituationWhat happensWhy
gcd⁡(m,n)=1\gcd(m,n)=1Standard Euler's theorem applies directlymφ(n)≡1(modn)m^{\varphi(n)}\equiv1\pmod n
mm a nonzero multiple of pp or qqStill correct, via CRT case split in the proofHandled by the p∣mp\mid m case, not by naive Euler
m=0m = 0c=0c=0, decrypts to 00Trivial case, consistent with the theorem
p=qp = qScheme breaks: wrong φ(n)\varphi(n), CRT fails, some messages unrecoverableSee counterexample above
ee not coprime to φ(n)\varphi(n)No valid dd exists; key generation failsInverses mod φ(n)\varphi(n) require gcd⁡(e,φ(n))=1\gcd(e,\varphi(n))=1
p,qp,q small or nn easily factoredScheme is correct but insecureCorrectness (this article) ≠\ne security (a separate, harder question)

The mathematician behind it

Origins · 1 minRonald L. Rivest, Adi Shamir, and Leonard M. Adleman and how this was discovered
RL
Ronald L. Rivest, Adi Shamir, and Leonard M. Adleman
Rivest b. 1947, Shamir b. 1952, Adleman b. 1945 · MIT, late 1970s

Ron Rivest, Adi Shamir, and Len Adleman were computer scientists at MIT working in the wake of Whitfield Diffie and Martin Hellman's 1976 proposal that public-key cryptography might be possible in principle. Rivest and Shamir generated candidate one-way functions; Adleman, a mathematician by training, tested them for weaknesses, breaking many proposals until the trapdoor based on modular exponentiation and factoring survived scrutiny. Their April 1977 result — refined and published in 1978 as "A Method for Obtaining Digital Signatures and Public-Key Cryptosystems" — gave the first concrete, efficiently implementable public-key scheme, and it won them the 2002 Turing Award.

History
- 1976: Diffie and Hellman propose the concept of public-key cryptography without a concrete trapdoor function.
- 1977: Rivest, Shamir, and Adleman devise the RSA trapdoor based on modular exponentiation and factoring.
- 1978: "A Method for Obtaining Digital Signatures and Public-Key Cryptosystems" is published in Communications of the ACM.
- 1983: MIT is granted US Patent 4,405,829 covering the RSA algorithm.
- 2000: The RSA patent expires, and the algorithm enters unrestricted public and open-source use.
Why does RSA require pp and qq to be distinct primes rather than just any two coprime numbers?

The correctness proof relies on Fermat's little theorem applied separately modulo pp and modulo qq, which requires pp and qq to be prime so that every nonzero residue is a unit. It also relies on the Chinese Remainder Theorem isomorphism Z/nZ≅Z/pZ×Z/qZ\mathbb{Z}/n\mathbb{Z}\cong\mathbb{Z}/p\mathbb{Z}\times\mathbb{Z}/q\mathbb{Z}, which requires pp and qq coprime; taking them equal (or sharing a factor) destroys this isomorphism. Additionally, using primes lets us compute φ(n)=(p−1)(q−1)\varphi(n)=(p-1)(q-1) by a simple closed formula. Composite "primes" would make φ(n)\varphi(n) harder to express and would generally make nn easier to factor, undermining security as well as breaking the proof's structure.

Does the correctness theorem prove RSA is secure?

No. Correctness is a statement of pure algebra: given the public and private keys as defined, decryption always undoes encryption, for every message in range. This is proven unconditionally using Euler's theorem and CRT, with no assumptions about computational hardness. Security is an entirely different, unproven claim: that no efficient algorithm, given only (n,e)(n,e) and cc, can recover mm or dd without factoring nn. No proof of this hardness exists; RSA's security rests on decades of failed attempts to break it and on the empirical difficulty of integer factorization, not on a theorem analogous to the correctness proof.

What happens if a message mm shares a common factor with nn?

Nothing goes wrong — RSA still decrypts correctly, though basic Euler's theorem alone does not explain why, since it requires gcd⁡(m,n)=1\gcd(m,n)=1. The full correctness proof splits into cases modulo pp and modulo qq separately: if p∣mp\mid m, then m≡0(modp)m\equiv0\pmod p and any positive power of mm is also 0(modp)0\pmod p, matching mm trivially; if p∤mp\nmid m, ordinary Fermat/Euler applies. Combining the two prime-power congruences via the Chinese Remainder Theorem shows med≡m(modn)m^{ed}\equiv m\pmod n regardless. In practice such messages are exceedingly rare (a message would have to be an exact multiple of the secret prime pp or qq), so this case is a proof subtlety more than a practical concern.

Why is the private exponent dd hard to compute from the public key alone?

Computing dd requires solving ed≡1(modφ(n))ed\equiv1\pmod{\varphi(n)}, which needs knowledge of φ(n)=(p−1)(q−1)\varphi(n)=(p-1)(q-1). Given only nn, computing φ(n)\varphi(n) is believed to be computationally equivalent in difficulty to factoring nn into pp and qq: if you know φ(n)\varphi(n) and nn, you can recover p+q=n−φ(n)+1p+q = n-\varphi(n)+1 and then solve a quadratic to get p,qp,q individually, and conversely knowing p,qp,q immediately gives φ(n)\varphi(n). Since no efficient (polynomial-time) factoring algorithm is known for large semiprimes n=pqn=pq, computing dd from (n,e)(n,e) alone is believed to be infeasible for suitably large primes.

Can RSA be used directly to encrypt long messages, like entire documents?

Not efficiently or safely in its raw "textbook" form as presented here. Messages must be encoded as integers strictly less than nn, so long documents must be broken into blocks, and textbook RSA applied block-by-block is vulnerable to several structural attacks (e.g. deterministic encryption reveals repeated blocks, and multiplicative structure enables chosen-ciphertext manipulations). In practice, RSA is used to encrypt a short random symmetric key, and the actual message is encrypted with a fast symmetric cipher (like AES) under that key — a hybrid scheme. Padding schemes such as OAEP are also layered on top of the raw RSA operation described in this article to achieve provable security guarantees.

Why must ee and dd be found using the extended Euclidean algorithm rather than by trial and error?

Because φ(n)\varphi(n) is typically an enormous number (hundreds of digits in real deployments), trial-and-error search for dd satisfying ed≡1(modφ(n))ed\equiv1\pmod{\varphi(n)} would be computationally infeasible. The extended Euclidean algorithm computes gcd⁡(e,φ(n))\gcd(e,\varphi(n)) and simultaneously expresses it as an integer combination ue+vφ(n)=gcd⁡(e,φ(n))ue+v\varphi(n)=\gcd(e,\varphi(n)); when this gcd is 11, reducing uu modulo φ(n)\varphi(n) gives dd directly, in a number of steps proportional to the logarithm of φ(n)\varphi(n), not to its size. This efficiency is essential — key generation must be fast even though φ(n)\varphi(n) has hundreds of digits.

Is the RSA correctness proof circular, since it uses Euler's theorem which is proved using group theory that predates RSA?

No circularity exists. Euler's theorem is a general fact about the multiplicative group of units modulo any integer, proved independently of RSA using only Lagrange's theorem or a direct counting argument on residues coprime to the modulus. RSA is a later, separate construction that applies this pre-existing theorem, together with the Chinese Remainder Theorem (also proved independently, from the structure of coprime moduli), to a specific setting: n=pqn=pq with chosen exponents e,de,d. The correctness proof never assumes any property of RSA to establish Euler's theorem or CRT; the dependency runs strictly one direction, from prerequisite theorems to the RSA correctness corollary.

Before this