Nexorasz
Number Theory & Cryptography Published September 16, 2026 • 16 min read

How Prime Numbers Protect the Internet: RSA Encryption, Modular Arithmetic, and One-Way Functions

In 1940, the British mathematician G.H. Hardy proudly declared in A Mathematician's Apology that number theory was pure, pristine, and wholly useless for warfare or practical industry. Little did Hardy realize that within four decades, the purest branch of number theory—the study of prime numbers, modular arithmetic, and Euler's totients—would become the multi-trillion-dollar bedrock of global commerce, online banking, military communications, and digital privacy.

Cryptographic padlock with binary matrix streams and RSA modular arithmetic formulas

Executive Summary & Cryptographic Architecture

  • The Key Exchange Breakthrough: In 1976, Whitfield Diffie and Martin Hellman solved the ancient symmetric key distribution bottleneck by introducing the concept of asymmetric public-key cryptography.
  • The RSA Algorithm (1977): Ronald Rivest, Adi Shamir, and Leonard Adleman implemented the first practical asymmetric cipher using prime factorization and modular exponentiation.
  • Computational Asymmetry: Multiplying two 1,024-bit primes p \times q = n requires less than a microsecond on a modern smartphone. Factoring the 2,048-bit modulus n back into p and q would require all classical supercomputers on Earth operating for billions of years.
  • Euler's Totient Engine: Knowledge of the prime factors gives the receiver access to \phi(n) = (p - 1)(q - 1), allowing calculation of the secret modular inverse private key d via the Extended Euclidean Algorithm.
  • The Post-Quantum Horizon: Shor's quantum algorithm can factor large integers in polynomial time. Global security agencies are actively transitioning to post-quantum lattice-based cryptography (ML-KEM / Kyber) to counter future quantum decryption.
Advertisement
Responsive Leaderboard Banner Container

1. The Historical Dilemma: The Symmetric Key Distribution Bottleneck

For three thousand years, cryptography was exclusively symmetric. Whether utilizing Julius Caesar's shift cipher, Renaissance polyalphabetic tables, or the Nazi Enigma machine, both the sender and the receiver had to share the exact same secret key (or codebook) before any secure transmission could occur.

This introduced the fatal Key Distribution Problem: how do two parties who have never met—such as your web browser and an e-commerce server located across the globe—safely exchange a secret encryption key across an open, untrusted telecommunications network without a spy intercepting it? In the pre-digital era, governments resolved this by sending couriers with locked briefcases handcuffed to their wrists. In an internet handling billions of transactions per second, physical couriers were impossible.

In 1976, Stanford researchers Whitfield Diffie and Martin Hellman proposed a revolutionary paradigm: asymmetric cryptography. They hypothesized a system with two mathematically linked keys: a public key used by anyone to lock (encrypt) messages, and a separate private key held exclusively by the recipient to unlock (decrypt) them. But Diffie and Hellman lacked the concrete one-way mathematical function required to build it.

2. Rivest, Shamir, and Adleman (1977): The Birth of RSA

In 1977, three researchers at MIT's Laboratory for Computer Science—mathematicians Ron Rivest and Adi Shamir, along with computer scientist Leonard Adleman—set out to prove that Diffie and Hellman's concept was impossible. Rivest and Shamir repeatedly proposed mathematical candidate functions, and Adleman systematically broke them.

After 42 unsuccessful attempts, Rivest spent Passover night in April 1977 contemplating prime number properties. By sunrise, he had scribbled the complete formal architecture for what would become the RSA Algorithm. When Adleman examined the proof, he could find no vulnerability. The algorithm was published in the August 1977 issue of Scientific American, accompanied by a challenge cipher that took the world's distributed computing networks 17 years to crack.

3. Trapdoor One-Way Functions: The Art of Computational Asymmetry

At the heart of asymmetric cryptography lies the concept of a Trapdoor One-Way Function. A function f(x) is one-way if calculating y = f(x) is computationally trivial, but finding x = f^{-1}(y) is practically impossible. A trapdoor is a secret piece of auxiliary information that makes inverting the function straightforward.

Trapdoor one-way function comparing microsecond multiplication with impossible factoring

RSA constructs its trapdoor from the fundamental computational asymmetry of prime numbers:

4. Step-by-Step Mathematical Walkthrough of RSA Key Generation

The complete mathematical protocol for generating an RSA key pair proceeds in five rigorous stages:

Asymmetric cryptography Alice and Bob protocol with public lock and private key

Step 1: Choose Two Distinct Massive Primes

The receiver (Bob) uses a cryptographically secure pseudo-random number generator (CSPRNG) combined with probabilistic primality tests (such as the Miller-Rabin algorithm) to generate two distinct, massive prime numbers: p and q.

Step 2: Calculate the Modulus

Bob computes the product of the two primes:

n = p \times q

The bit-length of n is the key length (e.g., 2,048 bits or 4,096 bits). The value n is made completely public.

Step 3: Compute Euler's Totient Function

Euler's totient function \phi(n) (phi) counts how many positive integers less than n are coprime to n. Because p and q are prime, this evaluates to:

\phi(n) = (p - 1)(q - 1)

This value is the secret trapdoor. Anyone who knows p and q can calculate \phi(n) instantly; anyone who only knows n cannot.

Step 4: Select the Public Exponent

Bob chooses an integer e such that 1 < e < \phi(n) and \gcd(e, \phi(n)) = 1 (coprime to totient). In modern cryptographic standards, e is almost universally set to the Fermat prime 65,537 (2^{16} + 1), which allows rapid modular exponentiation because its binary representation contains only two ones (10000000000000001_2).

Step 5: Calculate the Secret Private Exponent

Bob calculates d, the modular multiplicative inverse of e modulo \phi(n), using the Extended Euclidean Algorithm:

d \times e \equiv 1 \pmod{\phi(n)} \iff d \equiv e^{-1} \pmod{\phi(n)}

Bob publishes the Public Key: (e, n) and keeps the Private Key: (d, n) strictly secret. Bob immediately deletes p, q, and \phi(n) from memory so they can never be leaked.

5. Euler's Totient Theorem: The Engine That Unlocks the Cipher

How do these exponents encrypt and decrypt messages?

Suppose Alice wants to send a secret message m (converted into an integer 0 ≤ m < n) to Bob. Alice looks up Bob's public key (e, n) and computes the ciphertext c:

c \equiv m^e \pmod{n}

When Bob receives c, he raises it to his secret private exponent d:

c^d \equiv (m^e)^d \equiv m^{ed} \pmod{n}

Because e \cdot d \equiv 1 \pmod{\phi(n)}, there exists some integer k such that ed = k \cdot \phi(n) + 1. Substituting this in:

m^{ed} = m^{k \cdot \phi(n) + 1} = \left(m^{\phi(n)}\right)^k \cdot m^1 \pmod{n}

In 1736, Swiss genius Leonhard Euler generalized Fermat's Little Theorem to formulate Euler's Totient Theorem: if m and n are coprime, then:

m^{\phi(n)} \equiv 1 \pmod{n}

Applying Euler's theorem:

\left(m^{\phi(n)}\right)^k \cdot m \equiv (1)^k \cdot m \equiv \mathbf{m} \pmod{n}

The ciphertext dissolves, and the original plaintext message m emerges. The modular exponentiation cycles through the numbers and returns precisely to where it started.

6. A Concrete Numerical Example: Encrypting and Decrypting with Small Primes

To see the algorithm in action without multi-hundred-digit arithmetic, trace an example using small prime numbers:

  1. Choose Primes: Let p = 61 and q = 53.
  2. Compute Modulus: n = 61 \times 53 = 3233.
  3. Compute Totient: \phi(n) = (61 - 1)(53 - 1) = 60 \times 52 = 3120.
  4. Select Public Exponent: Choose e = 17, which is coprime to 3120 (\gcd(17, 3120) = 1).
  5. Calculate Private Exponent: Solve 17d \equiv 1 \pmod{3120} using the Extended Euclidean Algorithm: d = 2753 (since 17 \times 2753 = 46,801 = 15 \times 3120 + 1).

The Keys: Public Key is (17, 3233); Private Key is (2753, 3233).

7. The General Number Field Sieve (GNFS): Why 2048-Bit Keys Remain Unbroken

If an adversary knows n and e, why can't they simply factor n, calculate \phi(n), and deduce d?

The fastest known classical algorithm for factoring large composite integers is the General Number Field Sieve (GNFS). Its computational asymptotic time complexity is sub-exponential:

O\left(\exp\left(\left(\sqrt[3]{\frac{64}{9}} + o(1)\right) (\ln n)^{1/3} (\ln \ln n)^{2/3}\right)\right)

In 2020, an international consortium of computer scientists successfully factored RSA-250 (an 829-bit integer). The calculation required approximately 2,700 CPU core-years of computational processing.

However, RSA key lengths scale exponentially. Standard web traffic (TLS/HTTPS) uses RSA-2048 or RSA-4096. Factoring a 2,048-bit key using the GNFS requires roughly 2^{112} operations—equivalent to billions of years of runtime on all computing hardware on Earth running simultaneously. As long as key generation avoids weak pseudo-random seeds, classical computers cannot break properly implemented RSA-2048.

8. The Quantum Threat: Shor's Algorithm and the Death of Classical RSA

The classical invulnerability of RSA rests entirely on the unproven assumption that integer factorization is inherently intractable. In 1994, Bell Labs mathematician Peter Shor dealt public-key cryptography an existential shock.

Shor proved that a sufficiently powerful quantum computer can factor large integers in polynomial time:

O\left((\log n)^2 (\log \log n) (\log \log \log n)\right) \approx O(k^3)

Shor's algorithm achieves this by transforming factorization into an order-finding (period-finding) problem. Using the Quantum Fourier Transform (QFT), a quantum computer evaluates all modular exponentiation states in quantum superposition simultaneously, measuring the period of the sequence a^x \pmod{n} in seconds.

A fault-tolerant quantum computer equipped with roughly 4,000 logical qubits (requiring several million noisy physical qubits with quantum error correction) would crack RSA-2048 in a matter of hours. This threat has prompted intelligence agencies to warn of "Harvest Now, Decrypt Later" operations, where adversaries intercept encrypted data today and store it until quantum decryption hardware matures.

9. Post-Quantum Cryptography: Lattice Mathematics and Kyber

In response to the quantum horizon, the National Institute of Standards and Technology (NIST) conducted an eight-year global competition to select replacement algorithms for RSA. In August 2024, NIST released its finalized standards for Post-Quantum Cryptography (PQC).

The new standard for general encryption and key encapsulation is ML-KEM (derived from CRYSTALS-Kyber). Kyber does not rely on prime number factorization or discrete logarithms. Instead, it is built on Lattice-Based Cryptography—specifically the Learning With Errors (LWE) problem in multidimensional geometric lattices.

Finding the shortest vector in an 800-dimensional lattice with intentional noise injected is known to be intractable for both classical supercomputers and quantum algorithms. The era of prime-number RSA is steadily handing the torch to high-dimensional lattice geometry.

10. Cryptographic Paradigms Comparison Matrix

The table below compares the foundational cryptographic architectures securing the modern digital world:

Cryptographic Family Core Mathematical Hard Problem Standard Key Size Classical Security Quantum Vulnerability
RSA Large prime factorization (n = p × q) 2,048 – 4,096 bits Extremely High Vulnerable (Shor's Algorithm)
ECC (Elliptic Curve) Elliptic curve discrete logarithm problem (ECDLP) 256 – 384 bits Extremely High Vulnerable (Shor's Algorithm)
AES (Symmetric) Substitution-permutation network permutations 128 – 256 bits Unbroken Secure (Grover's only halves key length)
ML-KEM / Kyber (PQC) Module Learning With Errors (M-LWE) in lattices 800-dim vectors Extremely High Quantum-Resistant
Advertisement
In-Article Adaptive Ad Unit

11. Frequently Asked Questions

Why are prime numbers used in cryptography instead of composite numbers? ▼

Prime numbers serve as the fundamental indivisible building blocks of arithmetic. Multiplying two large prime numbers (p and q) produces a composite modulus (n) that has only two non-trivial factors in the entire universe: p and q. This unique property makes calculating Euler's totient \phi(n) trivial for someone who knows the primes, but practically impossible for an eavesdropper who only knows the product n.

What is a trapdoor one-way function? ▼

A trapdoor one-way function is a mathematical operation that is easy to compute in one direction, but extraordinarily difficult to reverse unless one possesses a specific piece of secret information called the "trapdoor". In RSA, multiplying two 1,024-bit primes takes less than a microsecond, while factoring the 2,048-bit product back into the original primes requires billions of CPU core-years on classical supercomputers.

How does Euler's Totient Theorem enable RSA decryption? ▼

Euler's Totient Theorem states that if \gcd(m, n) = 1, then m^{\phi(n)} \equiv 1 \pmod{n}. In RSA, the private exponent d is constructed such that e \cdot d \equiv 1 \pmod{\phi(n)}. When decrypting ciphertext c = m^e \pmod{n}, raising it to the power d yields c^d = (m^e)^d = m^{ed} = m^{k\phi(n) + 1} = (m^{\phi(n)})^k \cdot m = (1)^k \cdot m = m \pmod{n}, restoring the original message perfectly.

Will quantum computers break RSA encryption? ▼

Yes, sufficiently large, fault-tolerant quantum computers running Peter Shor's 1994 algorithm will break RSA by finding the period of modular exponentiation in polynomial time. To protect future infrastructure, NIST has standardized Post-Quantum Cryptography (PQC) algorithms based on lattice mathematics (such as ML-KEM / Kyber), which are resistant to both classical and quantum attacks.

What is the difference between symmetric and asymmetric encryption? ▼

Symmetric encryption (such as AES-256) uses the exact same secret key to both encrypt and decrypt data, which is fast but requires both parties to securely share the key beforehand. Asymmetric encryption (such as RSA) uses a mathematically linked key pair: a public key that anyone can use to encrypt data, and a private key kept strictly secret by the recipient to decrypt it.

Share this cybersecurity mathematics analysis: