June 2022 · Mathematics · 4 min read

Why Prime Numbers Are the Backbone of Everything You Encrypt

Every time you visit a website over HTTPS, send an encrypted message, or SSH into a server, prime numbers are doing the heavy lifting behind the scenes. If you work in security, primes aren't just a math curiosity. They're the reason cryptography works at all.

Let me explain why.

The one-way door

Pick two prime numbers. Say, 61 and 53. Multiply them together. You get 3,233. Easy.

Now go the other direction. I give you 3,233 and ask: what two primes were multiplied to produce this? That's harder. You'd have to try dividing by different primes until you find the answer.

With small numbers, it's doable. But what if I give you a number that's 600 digits long? Finding the two primes that produced it would take every computer on Earth longer than the age of the universe. Multiplying is easy. Factoring is absurdly hard.

This asymmetry is the entire foundation of RSA encryption, which protects most of the internet's traffic.

How RSA actually uses primes

RSA works like this: generate two massive prime numbers (we're talking 300+ digits each). Multiply them together to get a public key component. That product is public, everyone can see it. But the original two primes are your private key. Anyone can encrypt a message using the product, but only someone who knows the two original primes can decrypt it.

The security of RSA literally depends on one assumption: that nobody can efficiently factor large numbers back into their prime components. That's it. If someone figured out a fast way to factor large numbers, every RSA key on the planet would break overnight.

This is also why quantum computing is such a big deal for security. Shor's algorithm, running on a sufficiently powerful quantum computer, could factor large numbers exponentially faster than classical computers. That's not science fiction anymore. It's why NIST has been standardizing post-quantum cryptography algorithms.

So how do we find big primes?

If RSA needs huge primes, we need a way to find them. You can't just check every number by dividing it by everything smaller. That's called trial division, and it works fine for small numbers but falls apart fast.

The Sieve of Eratosthenes is a clever ancient algorithm. Start with a list of numbers, mark 2 as prime, then cross out every multiple of 2. Move to 3, cross out its multiples. Keep going. Whatever's left is prime. It's elegant, but it only works up to a certain size because you need to hold the entire list in memory.

For the massive primes RSA needs, we use probabilistic tests. The Miller-Rabin test is the workhorse here. It can't prove a number is prime with 100% certainty, but it can tell you "this number is prime with a probability of 99.9999...%." Run it enough times and the odds of being wrong are lower than the odds of a cosmic ray flipping a bit in your CPU.

There's also the AKS test, which is deterministic (it gives you a definitive yes or no), but it's slower. In practice, Miller-Rabin is what your TLS library is using when it generates RSA keys.

Why this matters to you

If you're in security, understanding primes isn't about doing math on a whiteboard. It's about understanding the assumptions your entire security stack rests on.

When someone asks "is RSA-2048 still safe?" they're really asking "can anyone factor a 617-digit number yet?" When people talk about quantum threats, they're talking about breaking the factoring assumption. When you see key sizes getting larger, it's because we need bigger primes to stay ahead.

Primes are the reason your secrets stay secret. That's worth understanding.

← Back to all posts