Number Theory and Public-Key Cryptography · Cryptography and Network Security

Fermat's Theorem

Watch lectures

Fermat's Theorem

1. Statement (beginner words!)

If pp is prime and aa is NOT a multiple of pp, then:

ap−1 mod p=1a^{p-1} \text{ mod } p = 1

Corolary (works for ALL aa):

ap mod p=aa^{p} \text{ mod } p = a

In words: powers cycle back to 1 every p−1p-1 steps mod prime!

2. Worked Examples (exam numericals!)

p = 5, a = 2: 2⁴ = 16, 16 mod 5 = 1 ✓
p = 7, a = 3: 3⁶ = 729, 729 mod 7 = 1 ✓ (729 = 7×104 + 1!)
shortcut: 2¹⁰⁰ mod 7? 100 = 6×16 + 4 → 2¹⁰⁰ = (2⁶)¹⁶ × 2⁴ ≡ 1¹⁶ × 16 ≡ 2 mod 7!

3. Why Crypto Cares

  • Primality hint: if an−1a^{n-1} mod n≠1n ≠ 1 for some aa, then nn is COMPOSITE (Fermat test base!).
  • Inverse shortcut:
a−1 mod p=ap−2 mod pa^{-1} \text{ mod } p = a^{p-2} \text{ mod } p

(used in RSA key gen!).

  • Powers reduce exponents mod p−1p-1 (fast mental math!).

4. Traps

  • Needs PRIME pp! (242⁴ mod 4=04 = 0, not 1 — 4 composite, theorem fails!).
  • Needs aa coprime to pp (aa multiple of pp → 0, not 1!).
  • Converse FALSE: some composites pass for all coprime aa (Carmichael numbers, e.g. 561 — need Miller-Rabin!).

5. Exam Points

  • State + verify (242⁴ mod 55) — 5 marks, very frequent.
  • Exponent-reduction numerical (21002¹⁰⁰ mod 77) — 5 marks, favourite.
  • Carmichael caveat — 3 marks, frequent viva.
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