Modular Arithmetic
1. Congruences (The Language of Crypto Math)
a≡b(modn) means n∣(a−b) — same remainder. Residue classes {0,1,…,n−1} form Zn:
Arithmetic respects congruences: if a≡b, c≡d, then a+c≡b+d, ac≡bd(modn) — so we can reduce ANY time mid-computation. Worked: 74mod11? 72=49≡5; 74≡52=25≡3. Never compute 2401 first — reduce early (exam time-saver).
2. Inverses, GCD, and When Division Works
a has inverse mod n ⟺ gcd(a,n)=1 (proof via Euclid, Module 3 Topic 1). Units form group Zn∗ of size ϕ(n).
Worked inverses: 3−1mod7: 3×5=15≡1 → 5. 2−1mod11: 2×6=12≡1 → 6. No inverse: 4mod8 (gcd=4): 4x≡1(mod8) has NO solution (LHS always even) — division by 4 illegal mod 8. Solving ax≡b: unique solution x≡a−1b iff gcd(a,n)=1; else 0 or gcd solutions (e.g. 4x≡4(mod8): x=1,3,5,7 — four solutions).
3. Exponent Rules: Fermat, Euler, Fast Power
- Fermat: ap−1≡1(modp) (p prime, $p
mid a)→reduceexponentsmodp-1$.
- Euler: aϕ(n)≡1(modn) (gcd(a,n)=1) → reduce exponents mod ϕ(n).
- Fast square-and-multiply: x13=x8+4+1 (13=11012): square chain x,x2,x4,x8 (3 squarings), multiply selected (2 mults) — O(loge) instead of O(e).
Worked RSA-style: 516mod17: Fermat →516≡1 directly. 3100mod7: 36≡1→3100=396⋅34≡1⋅81≡81≡4(mod7). 236mod35: ϕ(35)=24, gcd=1: 236=224⋅212≡212=4096≡4096−35×117=4096−4095=1? Check 35×117=4095 ✓ → 1. (Pattern: Euler reduction makes big exponents tiny.)
4. Modular Arithmetic Toolkit (Exam Crib)
| Tool |
Statement |
Use |
| Reduce early |
(a⋅b)modn=((amodn)(bmodn))modn |
Keep numbers small |
| Negative residues |
−3≡8(mod11) |
Subtraction without borrowing |
| Inverse via Euclid |
ax+ny=1⇒x=a−1 |
DH/RSA/AES key computations |
| Fermat reduction |
ae≡aemod(p−1)(modp) |
Fast exponent questions |
| CRT (Module 5) |
Split mod pq into mod p + mod q |
RSA speedup ×4, exam numericals |
Pitfall list: never divide without checking gcd; never reduce exponent mod n (reduce mod ϕ(n) or p−1, base mod n); a−bmodn add n first if negative.
Exam Points
- Congruence definition + reduce-early demo (74≡3(mod11)) — 2-mark opener.
- Inverse condition gcd(a,n)=1 with success (3−1=5 mod 7) and failure (4 mod 8) cases.
- Fermat/Euler exponent reduction numericals (3100≡4(mod7)) — favourite 5-marker.
- Square-and-multiply steps for x13; crib-table recall.