Modular Arithmetic: The 'Clock Math' That Powers Cryptography

If it's 10am and you wait 5 hours, it's 3pm — not 15pm. You just did modular arithmetic.

There is a lot of jargon around this one. Strip it away and the math is genuinely simple. If it's 10am and you wait 5 hours, it's 3pm — not 15pm. You just did modular arithmetic.

The notation

a mod n = remainder when a is divided by n. 17 mod 12 = 5.

Why it's useful

Hash functions, RSA encryption, error-detecting codes, day-of-week calculators.

Properties

Addition and multiplication work modulo n. Division needs care (modular inverse).

Pro tips

  • Zeller's congruence uses mod 7 to compute day-of-week for any date.
  • Calculator MOD button: 23 MOD 5 = 3.

Frequently asked questions

Where do programmers use modulo? Indexing circular arrays, even/odd checks, hash tables, time arithmetic.

What's modular exponentiation? Computing (a^b) mod n efficiently — backbone of RSA and Diffie-Hellman.

If you only remember one thing from this post, make it that the inputs matter more than the calculator.

Related