Look at a twelve-hour clock. It is four in the afternoon, and I ask you what time it will be in fourteen hours. You do not answer "eighteen o'clock". You answer six.
You just did modular arithmetic, and you did it without thinking. That reflex — numbers running off the end and wrapping back to the start — is the foundation of essentially every encryption system protecting you right now.
The one operation
Fix a number and call it the modulus. It is the size of the clock face. Every number is then replaced by its remainder after dividing by it.
25 mod 7 = 4
100 mod 9 = 1
That is the whole rule. Cryptography just uses enormous clock faces — hundreds of digits around.
Why wrapping hides things
Here is the part worth sitting with. Ordinary arithmetic leaks. Bigger inputs make bigger outputs, so if I show you a result you can reason backwards about what went in. Multiply something by a thousand and I can see the thousand in the size of the answer.
Wrapping destroys that. Once numbers fold around a large modulus, the output tells you almost nothing about the input. Watch what happens to consecutive powers of 3 modulo 17:
34 = 13 35 = 5 36 = 15
3, 9, 10, 13, 5, 15. No pattern. No upward march. Knowing that 3⁵ lands on 5 tells you nothing useful about where 3⁶ will land.
Now scale that to a modulus with 600 digits. Computing the power forwards takes a fraction of a second. Working backwards to find which exponent was used — the discrete logarithm problem — is something nobody on Earth knows how to do efficiently.
That gap is the product
Every public-key system is built on some operation that is easy in one direction and infeasible in the other. Modular exponentiation is the workhorse. It is why two strangers can agree on a secret key over a line everyone is listening to, and why the padlock in your address bar means anything at all.
Not because the maths is complicated. Because a clock does not tell you how many times it went around.
Try it yourself
Put any numbers into the modular exponentiation calculator and press "show steps" — you will see the square-and-multiply trick that keeps 600-digit arithmetic fast.
Open the calculator →Next week: why cryptography is obsessed with prime numbers, and how a 300-digit prime is found in the first place.
Get the next one by email
One concept from the mathematics of cryptography, visually explained, every week. Free forever.
Subscribe free →