
The Math Behind RSA #2: Modular Arithmetic — When Clock Math Becomes Cryptography
This article has a more math-focused version with formal proofs on Folio . In Part 1 , we explored prime numbers — the raw material of RSA. Now we need the machinery that makes RSA work: modular arithmetic . You already know modular arithmetic. Every time you look at a clock and say "3 hours after 11 is 2," you're doing it. The twist is that this simple idea — numbers that wrap around — turns out to be the foundation of modern cryptography. The Clock Analogy On a 12-hour clock, there's no "13 o'clock." After 12, you wrap back to 1. In math, we write: 13≡1(mod12) 13 \equiv 1 \pmod{12} 13 ≡ 1 ( mod 12 ) This reads "13 is congruent to 1, modulo 12." It means 13 and 1 have the same remainder when divided by 12. # Modular arithmetic in Python is just the % operator print ( 13 % 12 ) # 1 print ( 27 % 12 ) # 3 print ( 48 % 12 ) # 0 (exactly on the 12) More formally: a≡b(modn)a \equiv b \pmod{n} a ≡ b ( mod n ) means nn n divides (a−b)(a - b) ( a − b ) . That's it. That's the whole definition.
Continue reading on Dev.to Python
Opens in a new tab



