Folioby Interconnected
Log InSign Up

Number theory meets cryptography: why RSA works and what makes it secure

Every theorem in this series -- Fermat, Euler, the extended Euclidean algorithm, CRT -- corresponds to a component of the RSA cryptosystem. We trace each connection, work through a concrete example, and discuss the factoring barrier that underpins RSA's security.

FO
Folio Official
March 1, 2026

Number theory was long celebrated as the purest branch of mathematics – beautiful, ancient, and seemingly devoid of practical application. That reputation changed in 1977, when Rivest, Shamir, and Adleman combined several classical theorems into a public-key cryptosystem that transformed the way the world communicates securely. In this final article, we trace how each theorem from this series feeds into the RSA cryptosystem.

1 The idea behind public-key cryptography

Remark 1 (The key-distribution problem).
Traditional (symmetric-key) cryptography requires the sender and receiver to share a secret key. But sharing a key securely requires an already-secure channel – a chicken-and-egg problem.

Public-key cryptography resolves this dilemma using a one-way function: an operation that is easy to perform but hard to reverse. Think of a padlock: anyone can snap it shut, but only the keyholder can open it.

2 How RSA works

Definition 2 (RSA key generation).
  1. Choose two large random primes p and q, and compute n=pq.

  2. Compute φ(n)=(p−1)(q−1) (Euler's totient function).

  3. Choose e with gcd(e,φ(n))=1 (the standard choice is e=65537).

  4. Compute d satisfying ed≡1(modφ(n)) (via the extended Euclidean algorithm).

Public key: (n,e). Private key: d.
Remark 3.
Let us identify the tools used in this construction:
  • Primes (Article 3): the choice of p and q.

  • Euler's totient function (Article 4): computing φ(n).

  • Extended Euclidean algorithm (Article 2): computing d.

Definition 4 (RSA encryption and decryption).
Represent the plaintext as an integer m with 0≤m<n.
  • Encryption: c≡me(modn) (using the public key e).

  • Decryption: m≡cd(modn) (using the private key d).

3 Why decryption recovers the plaintext: Euler's theorem is the key

Why does cd≡m(modn) hold?

Theorem 5 (Correctness of RSA).
If gcd(m,n)=1, then (me)d≡m(modn).
Proof.
Since ed≡1(modφ(n)), write ed=1+kφ(n) for some integer k. Then
(me)d=med=m1+kφ(n)=m⋅(mφ(n))k.
By Euler's theorem (Article 4), mφ(n)≡1(modn). Therefore
(me)d≡m⋅1k=m(modn).
□
Remark 6.
When gcd(m,n)=1 (that is, p∣m or q∣m), the identity (me)d≡m(modn) still holds. This can be verified by working modulo p and modulo q separately and combining the results using the Chinese Remainder Theorem (Article 5).

4 The security guarantee: the hardness of factoring

Remark 7 (Why RSA is secure).
An attacker knows the public key (n,e) but needs the private key d. Computing d requires φ(n)=(p−1)(q−1), and knowing φ(n) requires factoring n into p×q.

The hardness of integer factorization: computing n=p×q is instantaneous, but recovering p and q from n (when both are large) is, by all known classical algorithms, extraordinarily expensive. This asymmetry is the foundation of RSA's security.
Remark 8 (The computational gap).
  • Multiplication: p×q runs in O((logn)2) time – trivial.

  • Factoring: the fastest known classical algorithm (the general number field sieve) runs in exp(O((logn)1/3(loglogn)2/3))– sub-exponential but still infeasible for large n.

  • Factoring a 2048-bit modulus n is estimated to take thousands of years with current hardware.

It is this asymmetry – multiplication is easy but factoring is hard– that sustains the security of RSA.

5 How each article contributes to RSA

Remark 9 (The theorems of this series at work).
Every article in this series corresponds to a component of the RSA system:

  • Article 1 (Modular arithmetic): all RSA computations live in the world of modn.

  • Article 2 (Euclidean algorithm): the private key d is computed as the modular inverse of e modulo φ(n).

  • Article 3 (Fundamental Theorem of Arithmetic): the uniqueness of prime factorization is the premise on which security rests.

  • Article 4 (Fermat–Euler): Euler's theorem proves that decryption recovers the plaintext.

  • Article 5 (Chinese Remainder Theorem): CRT-RSA performs decryption modulo p and modulo q separately, then combines, for a significant speedup.

  • Article 6 (Quadratic residues): the Rabin cryptosystem (a variant of RSA) rests on the theory of quadratic residues.

  • Article 7 (Continued fractions): Wiener's attack on RSA with a small private key d uses continued fractions to crack the system.

6 A worked example

Example 10 (RSA with small numbers).
  1. Key generation: p=61, q=53; n=3233; φ(n)=60×52=3120.

  2. Choose e=17 (gcd(17,3120)=1).

  3. Extended Euclidean algorithm: 17d≡1(mod3120) yields d=2753 (since 17×2753=46801=15×3120+1).

  4. Encryption: m=65⇒c≡6517(mod3233)=2790.

  5. Decryption: 27902753mod3233=65 (computed by repeated squaring).

7 Looking ahead: the quantum threat

Remark 11 (Quantum computers and RSA).
Shor's algorithm factors integers in polynomial time on a quantum computer. If a sufficiently powerful quantum machine is built, RSA will be broken. This prospect has spurred intense research into post-quantum cryptography– lattice-based, code-based, isogeny-based, and other schemes believed to resist quantum attacks.
Remark 12.
Yet even if RSA were to fall, the mathematical beauty underlying it would remain intact. Modular arithmetic, the Euclidean algorithm, Fermat's little theorem, the Chinese Remainder Theorem – these are truths that have stood for millennia and will continue to find applications far beyond cryptography.

8 Series summary

Remark 13.
Let us look back over the eight articles of this Number Theory "Between the Lines" series:
  1. Modular arithmetic: the projection that discards information. The ring Z/nZ.

  2. The Euclidean algorithm: an O(log)-time algorithm built on an invariant. Bé

  3. The Fundamental Theorem of Arithmetic: uniqueness of prime factorization, resting on Euclid's lemma.

  4. Fermat's little theorem: the group structure of (Z/pZ)∗. The inverse ap−2.

  5. The Chinese Remainder Theorem: divide and conquer in algebra. Z/mnZ≅Z/mZ×Z/nZ.

  6. Quadratic residues: the 2-to-1 nature of x↦x2. The law of quadratic reciprocity.

  7. Continued fractions: the Euclidean algorithm from another angle. Best rational approximations and Pell's equation.

  8. RSA cryptography: the confluence of every theorem in the series.

Number theory begins with the simplest objects imaginable – the integers 1,2,3,…– yet it reveals structures of astonishing depth and breadth. If this series has shed light on the "why" that textbooks leave between the lines, it has served its purpose.
Number TheoryMathematicsBetween the Lines
FO
Folio Official

Mathematics "between the lines" — exploring the intuition textbooks leave out, written in LaTeX on Folio.

1 followers·107 articles
Number Theory — Between the LinesPart 8 of 8
Previous
Continued fractions: how to find the best rational approximation to any number
No next article

Share your expertise with the world

Write articles with LaTeX support, build your audience, and earn from your knowledge.

Start Writing — It's Free

More from Folio Official

Folio Official·March 1, 2026

Why primes are the atoms of the integers: what the Fundamental Theorem of Arithmetic really says

Unique prime factorization is not as obvious as it seems. Through a counterexample in Z[sqrt(-5)], we witness uniqueness break down, then prove both the existence and uniqueness parts of the Fundamental Theorem, and survey the Sieve of Eratosthenes and the linear sieve.

Number TheoryMathematicsBetween the Lines
Folio Official·March 1, 2026

The Chinese Remainder Theorem: why simultaneous congruences can be merged

We view CRT as the number-theoretic incarnation of divide-and-conquer, prove the ring isomorphism Z/mnZ = Z/mZ x Z/nZ, and show how Garner's algorithm avoids overflow in practice.

Number TheoryMathematicsBetween the Lines
Folio Official·March 1, 2026

What does it mean to "divide evenly"? Why number theory begins with mod

The modular reduction map is a projection that deliberately discards information. Clocks, days of the week, and the competitive-programming modulus 10^9+7 all share the same algebraic structure. From the definition of divisibility through congruences to the ring Z/nZ, we uncover the reason number theory starts where it does.

Number TheoryMathematicsBetween the Lines
Folio Official·March 1, 2026

Why the Euclidean algorithm finds the greatest common divisor: from subtraction to division

The recursion gcd(a,b) = gcd(b, a mod b) hides an invariant: the set of common divisors never changes. Starting from a naive subtraction-based method and upgrading to division, we derive Bezout's identity, the extended Euclidean algorithm, and modular inverses.

Number TheoryMathematicsBetween the Lines