Finite Fields and Confidentiality · Cryptography and Network Security

Euclid's Algorithm

Watch lectures

Euclid's Algorithm

1. GCD and Why Crypto Needs It

gcd⁡(a,b)\gcd(a, b) = largest dd dividing both. Crypto uses it to test invertibility (a−1 mod na^{-1} \bmod n exists ⟺ gcd⁡(a,n)=1\gcd(a,n) = 1), to compute the inverse itself, and inside RSA key generation (gcd⁡(e,ϕ(n))=1\gcd(e, \phi(n)) = 1), primality helpers, and polynomial fields.

d=gcd⁡(a,b)  ⟺  d∣a,  d∣b,  and any common divisor c∣dd = \gcd(a,b) \iff d \mid a,\; d \mid b,\; \text{and any common divisor } c \mid d

Worked intuition: gcd⁡(48,18)\gcd(48, 18): divisors of 48: 1,2,3,4,6,8,12,16,24,481,2,3,4,6,8,12,16,24,48; of 18: 1,2,3,6,9,181,2,3,6,9,18 → common max 66.

2. Basic Euclid (Worked)

Theorem: gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a, b) = \gcd(b, a \bmod b). Repeatedly replace until remainder 00:

gcd(252, 198):
252 = 1×198 + 54  → gcd(198, 54)
198 = 3×54 + 36   → gcd(54, 36)
54  = 1×36 + 18   → gcd(36, 18)
36  = 2×18 + 0    → gcd = 18 ✓

Only 44 divisions for 3-digit numbers — complexity O(log⁡min⁡(a,b))O(\log \min(a,b)) (Lamé: steps ≤5×\le 5 \times digits). Second trace (exam-size): gcd⁡(1970,1066)\gcd(1970, 1066): 1970=1×1066+9041970 = 1 \times 1066 + 904; 1066=1×904+1621066 = 1 \times 904 + 162; 904=5×162+94904 = 5 \times 162 + 94; 162=1×94+68162 = 1 \times 94 + 68; 94=1×68+2694 = 1 \times 68 + 26; 68=2×26+1668 = 2 \times 26 + 16; 26=1×16+1026 = 1 \times 16 + 10; 16=1×10+616 = 1 \times 10 + 6; 10=1×6+410 = 1 \times 6 + 4; 6=1×4+26 = 1 \times 4 + 2; 4=2×2+04 = 2 \times 2 + 0 → gcd⁡=2\gcd = 2.

3. Extended Euclid: Bézout + Inverses (The Money Section)

Extended Euclid finds x,yx, y with Bézout identity:

ax+by=gcd⁡(a,b)ax + by = \gcd(a, b)

If gcd⁡(a,n)=1\gcd(a, n) = 1: ax+ny=1⇒ax≡1(modn)ax + ny = 1 \Rightarrow ax \equiv 1 \pmod n → x mod n=a−1x \bmod n = a^{-1}.

Worked inverse: 7−1 mod 407^{-1} \bmod 40 (RSA-style: e=7e = 7, ϕ=40\phi = 40). Euclid: 40=5×7+540 = 5 \times 7 + 5; 7=1×5+27 = 1 \times 5 + 2; 5=2×2+15 = 2 \times 2 + 1; 2=2×1+02 = 2 \times 1 + 0. Back-substitute: 1=5−2×21 = 5 - 2 \times 2; 2=7−1×52 = 7 - 1 \times 5 → 1=5−2(7−5)=3×5−2×71 = 5 - 2(7 - 5) = 3 \times 5 - 2 \times 7; 5=40−5×75 = 40 - 5 \times 7 → 1=3(40−5×7)−2×7=3×40−17×71 = 3(40 - 5 \times 7) - 2 \times 7 = 3 \times 40 - 17 \times 7. So x=−17≡23(mod40)x = -17 \equiv 23 \pmod{40}: 7−1=237^{-1} = 23. Check: 7×23=161=4×40+17 \times 23 = 161 = 4 \times 40 + 1 ✓.

Tabular shortcut (fewer errors): track (r,x)(r, x) rows: (40,0)(40, 0), (7,1)(7, 1); quotient q=5q = 5 → row (5,0−5×1=−5)(5, 0 - 5 \times 1 = -5); q=1q = 1 → (2,1−1(−5)=6)(2, 1 - 1(-5) = 6); q=2q = 2 → (1,−5−2×6=−17)(1, -5 - 2 \times 6 = -17) → inverse −17≡23-17 \equiv 23 ✓. Same answer, mechanical.

4. Uses and Pitfalls

  • RSA: d=e−1 mod ϕ(n)d = e^{-1} \bmod \phi(n) exactly as above; gcd⁡(e,ϕ)=1\gcd(e, \phi) = 1 check first — if $
    e 1,picknew, pick new e$.
  • Polynomial version (same algorithm, degree replaces size) gives AES GF(28)GF(2^8) inverses (Topic 4).
  • Binary/GCDвлека: never "divide" mod nn without gcd⁡=1\gcd = 1; negative xx always reduced +n+n; Euclid on (0,n)(0, n) returns nn.

Exam Points

  • Remainder-chain trace (gcd⁡(252,198)=18\gcd(252,198) = 18) — 2–3 mark opener.
  • Extended back-substitution to 7−1=23 mod 407^{-1} = 23 \bmod 40 with check 7×23=161≡17 \times 23 = 161 \equiv 1 — favourite 5-marker.
  • Bézout statement + "inverse ⟺ gcd 1" condition.
  • Table method as safe alternative; RSA dd link.
AI LearningWeb Platform

Coursify — Personal AI Course Generator

Struggling with a difficult subject or concept? Turn any engineering topic into a structured course with interactive lessons, quizzes, and research-backed explanations.

← All Cryptography and Network Security modules