Applications of Number Theory in Computer Security
Primality testing and RSA. A hands-on tour of the mathematics that protects every HTTPS page, SSH login and phone update, with every number on this page computed live in your browser.
Multiplying two primes is instant. Undoing it is not.
Modern security relies on maths that is easy to compute forwards and extremely hard to reverse. Try it: forge two primes, multiply them, then ask the computer to find them again from the product alone.
| Digits per prime | Divisions to factor | Time |
|---|
Each extra digit makes trial division about ten times slower. Real RSA uses primes of about 309 digits, so the product has about 617. Trial division would need around 10308 divisions; even the best known method, the general number field sieve, is hopeless at that size.
Every number splits into primes in exactly one way
An integer p > 1 is prime if only 1 and p divide it. Primes are the atoms of the whole numbers: every n > 1 is a product of primes, and that product is unique apart from order.
The theorem promises the factors exist, but gives no fast way to find them. Cryptography lives in that gap between “they exist” and “finding them is hard”.
Watch the primes below 100 appear
Euclid finds a gcd in a handful of steps
The greatest common divisor rests on one rule: gcd(a, b) = gcd(b, a mod b), and gcd(a, 0) = a. Geometrically, you cut the largest squares you can from an a × b rectangle; the last square that tiles what is left has side gcd(a, b).
| Step | Division | Remainder |
|---|
By Lamé's theorem the number of steps grows only with the number of digits, so this stays fast for numbers with hundreds of digits. Run backwards, it becomes the extended Euclidean algorithm: it finds x, y with ax + by = gcd(a, b) (Bézout), which is how RSA computes its private key.
Huge powers, tamed by repeated squaring
We write a ≡ b (mod n) when n divides a − b. Reducing mod n after every step keeps numbers small, and squaring repeatedly reaches ak in about 2·log₂k multiplications instead of k − 1.
| Power | Value mod n |
|---|
Fermat's test catches impostors, except Carmichael numbers
Used backwards it becomes a test: if an−1 ≢ 1 (mod n) for some base a, then n is certainly composite, and we learn this without finding a single factor. That base a is a Fermat witness.
The blind spot. 561 = 3 · 11 · 17 has no repeated prime, and 2, 10 and 16 (each p − 1) all divide 560. So a560 ≡ 1 mod 3, mod 11 and mod 17, hence mod 561, for every base coprime to 561 (Korselt's criterion). Alford, Granville and Pomerance proved in 1994 there are infinitely many such numbers.
Miller–Rabin listens for a fake square root of 1
Key fact: if p is prime, x² ≡ 1 (mod p) has only the solutions x ≡ ±1, because p | (x − 1)(x + 1). Write n − 1 = 2s·d with d odd, compute ad, then square s − 1 more times. A prime must start at 1 or pass through −1 (that is, n − 1).
How sure can we be?
For composite n, at most 1/4 of bases fail to expose it (Rabin, 1980), so k independent rounds leave an error of at most (1/4)k.
def miller_rabin(n, bases):
if n < 2: return False
if n in (2, 3): return True
if n % 2 == 0: return False
d, s = n - 1, 0
while d % 2 == 0: # write n-1 = 2^s * d
d //= 2; s += 1
for a in bases:
x = pow(a, d, n)
if x in (1, n - 1): continue
for _ in range(s - 1):
x = pow(x, 2, n)
if x == n - 1: break
else:
return False # a is a witness: n is composite
return True # probably prime| n | Truth | Fermat (2, 5, 7) | Miller–Rabin (2, 3, 5, 7) |
|---|---|---|---|
| 97 | prime | probably prime | probably prime |
| 221 | 13 · 17 | composite, witness 2 | composite, witness 2 |
| 561 | 3 · 11 · 17 | probably prime (wrong) | composite, witness 2 |
Forge an RSA key, then lock a message with it
Encrypt and decrypt
Euler's theorem guarantees the message comes back
Euler's theorem: if gcd(a, n) = 1 then aφ(n) ≡ 1 (mod n). For n = pq, φ(n) = (p − 1)(q − 1). Step through the proof; the live numbers use the key you forged above.
Our key breaks in a blink. A real one does not.
Toy: n = 3233
Trial division needs only primes up to √3233 ≈ 57.
Real: 2048 bits
About 617 digits. NIST SP 800-57 recommends at least this. The record, RSA-250 (829 bits), fell in 2020.
Textbook RSA leaks patterns
Encrypted letter by letter, the same letter always gives the same ciphertext, so it is only a substitution cipher. Type something:
Same input, same output
Fix: randomised padding such as OAEP before encrypting.
Very small private key d
Wiener's attack can recover it. Choose parameters by current guidance.
Shared modulus n
Two users with the same n can expose keys. Generate independent pairs.
p and q too close
Fermat's factorisation method splits n quickly. Generate primes independently.
RSA today, and what comes next
RSA
Public key: mainly digital signatures; key transport in legacy systems.
Session key
A short-lived symmetric key for one connection.
AES
Fast symmetric cipher for the bulk data.
TLS 1.3 no longer uses RSA key transport; keys are agreed with (EC)DHE, with post-quantum hybrids emerging.
Shor's algorithm (1997)
A large fault-tolerant quantum computer could factor quickly. None exists yet.
Harvest now, decrypt later
Data recorded today could be decrypted by a future machine.
Post-quantum systems, many built on lattices, are being standardised. Modular arithmetic, fast exponentiation and primality testing carry over.
What we showed
Primes make RSA work. Multiplying is easy; factoring the product is the hard problem.
Testing beats factoring. Miller–Rabin catches composites like 561 that fool Fermat.
Euclid builds the key. gcd(e, φ) = 1, and the extended version gives d.
Euler guarantees it. 65 → 2790 → 65, for every message, every time.
We can prove that RSA decrypts correctly, but its security rests on factoring staying hard, and that assumption must be rechecked as algorithms and quantum computers improve.
Questions?
We thank Dr. Mohammad Nasser for his guidance and support throughout this project.
All four members take part in the oral presentation.
References
- Agrawal, Kayal & Saxena (2004). PRIMES is in P. Annals of Mathematics 160(2).
- Alford, Granville & Pomerance (1994). There are infinitely many Carmichael numbers. Annals of Mathematics 139(3).
- Barker (2020). NIST SP 800-57 Part 1 Rev. 5, Recommendation for Key Management.
- Burton (2010). Elementary Number Theory, 7th ed. McGraw-Hill.
- Diffie & Hellman (1976). New directions in cryptography. IEEE Trans. Inf. Theory 22(6).
- Menezes, van Oorschot & Vanstone (1996). Handbook of Applied Cryptography. CRC Press.
- Miller (1976). Riemann's hypothesis and tests for primality. JCSS 13(3).
- Rabin (1980). Probabilistic algorithm for testing primality. J. Number Theory 12(1).
- Rivest, Shamir & Adleman (1978). A method for obtaining digital signatures and public-key cryptosystems. CACM 21(2).
- Rosen (2011). Elementary Number Theory and Its Applications, 6th ed. Pearson.
- Shor (1997). Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer. SIAM J. Comput. 26(5).
- Solovay & Strassen (1977). A fast Monte-Carlo test for primality. SIAM J. Comput. 6(1).