Virtual laboratory/Mathematics/Cryptography/Modular arithmetic — the clock

Modular arithmetic — the clock

Modular arithmetic "wraps" numbers around a circle, like the hand of a clock. Change the modulus and the number, and see the remainder — the foundation of cryptography.

Modular arithmetic — the clock
Mathematics · Cryptography · Modular arithmetic — the clock
Modulus nn12
Number aa9
In arithmetic modulo 12 (like on a clock), the result of 15 mod 1215 \bmod 12 is…
modulus n
12
number a
9
laps q
0
remainder a mod n
9
🎯 Challenge: compute the remainder
streak: 0

I’ll give you a number a and a modulus n — compute the remainder a mod n (what is left after the full laps).

What just happened?

The hand moved aa steps around a dial with nn positions. Each time it reaches the end it returns to the start — only where it finally stops matters. That position is the remainder of the division.

Definition — the modular remainder:

a mod n=r,a=(a÷n)⋅n+r,0≤r<na \bmod n = r,\qquad a = (a \div n)\cdot n + r,\qquad 0 \le r < n

We say that a≡r(modn)a \equiv r \pmod{n} (“a is congruent to r modulo n”) when aa and rr give the same remainder when divided by nn. In short: they differ by a multiple of nn.

The clock analogy:

A 12-hour clock counts modulo 12. 15:00 is 15 mod 12=315 \bmod 12 = 3, i.e. 3:00 in the afternoon — one full lap of the dial plus 3 hours. Likewise 27 mod 12=327 \bmod 12 = 3 (two laps and 3).

Why is this used in cryptography?

The Caesar cipher shifts letters modulo 26 (the alphabet “wraps” from Z to A). RSA and the Diffie–Hellman key exchange rely on exponentiation modulo a large number — operations on the circle of remainders are reversible only for someone who knows the key. Without modular arithmetic there is no modern encryption.

Why you need this for the exam:

Problems with remainders, divisibility and periodicity (e.g. “what day of the week in 100 days”, the last digit of a power) you solve with one trick: compute a mod na \bmod n. Write down nn, compute the remainder — the remainder governs the whole cycle.

Remember: a mod na \bmod n is the remainder of a division — a number on a circle of nn positions, where 0≤r<n0 \le r < n. It is the foundation of cryptography.

Illustrative model · NexTutor Virtual Laboratory

Enjoyed the experiment? Share it.

It's free — send it to friends from school.

Theory & formulas

Remainder of a division

a mod na\bmod n is the remainder of dividing aa by nn — numbers "wrap around" a circle like the hours on a clock.

Example

15 mod 12=315\bmod 12=3 (just as 15:0015{:}00 is 3:003{:}00 in the afternoon)

Congruences

The notation a≡b (mod n)a\equiv b\ (\mathrm{mod}\ n) means that nn divides a−ba-b. The operations +,−,⋅+,-,\cdot are compatible with remainders — this is the basis of the Caesar cipher and RSA.

Notation: aa a number, nn the modulus, a mod na\bmod n the remainder of the division.

Frequently asked questions

›

What is 15 mod 12?

3 — just as 15:00 is 3:00 in the afternoon; the remainder of dividing 15 by 12.

›

What is modular arithmetic used for?

It is the basis of cryptography (the Caesar cipher, RSA) and of number theory — operations on remainders.

Teaching? Embed this experiment on your site.

Free widget — paste it on your school site, blog or notes. It links to the full version.

Teaching a class or tutoring? Guide students in NexTutor →