Block Ciphers · Cryptography and Network Security

Modular Arithmetic

Watch lectures

Modular Arithmetic

1. Congruences (The Language of Crypto Math)

a≡b(modn)a \equiv b \pmod n means n∣(a−b)n \mid (a-b) — same remainder. Residue classes {0,1,…,n−1}\{0, 1, \dots, n-1\} form Zn\mathbb{Z}_n:

a≡b(modn)  ⟺  a=b+kn for some k∈Za \equiv b \pmod n \iff a = b + kn \text{ for some } k \in \mathbb{Z}

Arithmetic respects congruences: if a≡ba \equiv b, c≡dc \equiv d, then a+c≡b+da+c \equiv b+d, ac≡bd(modn)ac \equiv bd \pmod n — so we can reduce ANY time mid-computation. Worked: 74 mod 117^{4} \bmod 11? 72=49≡57^2 = 49 \equiv 5; 74≡52=25≡37^4 \equiv 5^2 = 25 \equiv 3. Never compute 24012401 first — reduce early (exam time-saver).

2. Inverses, GCD, and When Division Works

aa has inverse mod nn ⟺ gcd⁡(a,n)=1\gcd(a, n) = 1 (proof via Euclid, Module 3 Topic 1). Units form group Zn∗\mathbb{Z}_n^* of size ϕ(n)\phi(n).

Worked inverses: 3−1 mod 73^{-1} \bmod 7: 3×5=15≡13 \times 5 = 15 \equiv 1 → 55. 2−1 mod 112^{-1} \bmod 11: 2×6=12≡12 \times 6 = 12 \equiv 1 → 66. No inverse: 4 mod 84 \bmod 8 (gcd⁡=4\gcd = 4): 4x≡1(mod8)4x \equiv 1 \pmod 8 has NO solution (LHS always even) — division by 4 illegal mod 8. Solving ax≡bax \equiv b: unique solution x≡a−1bx \equiv a^{-1}b iff gcd⁡(a,n)=1\gcd(a,n) = 1; else 00 or gcd⁡\gcd solutions (e.g. 4x≡4(mod8)4x \equiv 4 \pmod 8: x=1,3,5,7x = 1, 3, 5, 7 — four solutions).

3. Exponent Rules: Fermat, Euler, Fast Power

  • Fermat: ap−1≡1(modp)a^{p-1} \equiv 1 \pmod p (pp prime, $p
    mid a)→reduceexponentsmod) → reduce exponents mod p-1$.
  • Euler: aϕ(n)≡1(modn)a^{\phi(n)} \equiv 1 \pmod n (gcd⁡(a,n)=1\gcd(a,n) = 1) → reduce exponents mod ϕ(n)\phi(n).
  • Fast square-and-multiply: x13=x8+4+1x^{13} = x^{8+4+1} (13=1101213 = 1101_2): square chain x,x2,x4,x8x, x^2, x^4, x^8 (3 squarings), multiply selected (2 mults) — O(log⁡e)O(\log e) instead of O(e)O(e).

Worked RSA-style: 516 mod 175^{16} \bmod 17: Fermat →516≡1\to 5^{16} \equiv 1 directly. 3100 mod 73^{100} \bmod 7: 36≡1→3100=396⋅34≡1⋅81≡81≡4(mod7)3^6 \equiv 1 \to 3^{100} = 3^{96} \cdot 3^4 \equiv 1 \cdot 81 \equiv 81 \equiv 4 \pmod 7. 236 mod 352^{36} \bmod 35: ϕ(35)=24\phi(35) = 24, gcd⁡=1\gcd = 1: 236=224⋅212≡212=4096≡4096−35×117=4096−4095=12^{36} = 2^{24} \cdot 2^{12} \equiv 2^{12} = 4096 \equiv 4096 - 35 \times 117 = 4096 - 4095 = 1? Check 35×117=409535 \times 117 = 4095 ✓ → 11. (Pattern: Euler reduction makes big exponents tiny.)

4. Modular Arithmetic Toolkit (Exam Crib)

Tool Statement Use
Reduce early (a⋅b) mod n=((a mod n)(b mod n)) mod n(a \cdot b) \bmod n = ((a \bmod n)(b \bmod n)) \bmod n Keep numbers small
Negative residues −3≡8(mod11)-3 \equiv 8 \pmod{11} Subtraction without borrowing
Inverse via Euclid ax+ny=1⇒x=a−1ax + ny = 1 \Rightarrow x = a^{-1} DH/RSA/AES key computations
Fermat reduction ae≡ae mod (p−1)(modp)a^e \equiv a^{e \bmod (p-1)} \pmod p Fast exponent questions
CRT (Module 5) Split mod pqpq into mod pp + mod qq RSA speedup ×4, exam numericals

Pitfall list: never divide without checking gcd⁡\gcd; never reduce exponent mod nn (reduce mod ϕ(n)\phi(n) or p−1p-1, base mod nn); a−b mod na - b \bmod n add nn first if negative.

Exam Points

  • Congruence definition + reduce-early demo (74≡3(mod11)7^4 \equiv 3 \pmod{11}) — 2-mark opener.
  • Inverse condition gcd⁡(a,n)=1\gcd(a,n) = 1 with success (3−1=53^{-1} = 5 mod 7) and failure (44 mod 88) cases.
  • Fermat/Euler exponent reduction numericals (3100≡4(mod7)3^{100} \equiv 4 \pmod 7) — favourite 5-marker.
  • Square-and-multiply steps for x13x^{13}; crib-table recall.
Free AppAndroid App

Coursify Android App

Generate AI courses, take quick quizzes between classes, and master complex engineering concepts on the go.

← All Cryptography and Network Security modules