Hypothesis $\text{gcd}(x,n) = 1$ if and only if $x$ has a multiplicative inverse in $\mathbb{Z}_n$
Note that "if and only if" means that we have an equivalence. So the hypothesis is $A \Leftrightarrow B$, where $A$ is "$\text{gcd}(x,n) = 1$" and $B$ is "$x$ has a multiplicative inverse in $\mathbb{Z}_n$". So to prove this, we need to prove:$\text{gcd}(x,n) = 1$ implies $x$ has a multiplicative inverse in $\mathbb{Z}_n$
We will only sketch that part, as we simply don't have time to do more right now.Algorithm: GCD(u,v) - [The Euclidean GCD algorithm] Inputs: integers u and v such that 0 ≤ v ≤ u, and u ≠ 0 Output: g where the gcd of u and v if v = 0 g = u else q,r = div(u,v) g = GCD(v,r) return g |
Example
u v q r g
--------------------------
51 42 1 9
42 9 4 6
9 6 1 3
6 3 2 0
3 0 3 ← g=3 gets passed all the
way back up. gcd(51,42) = 3
|
$(g,s,t) = \text{egcd}(u,v)$, where $g$ is the gcd of u and v, and $g = s\cdot u + t\cdot v$.
Algorithm: eGCD(u,v) - [The Extended Euclidean GCD algorithm] Inputs: integers u and v such that 0 ≤ v ≤ u, and u ≠ 0 Output: g,s,t where the gcd of u and v and g = s u + t v if v = 0 g,s,t = u,1,0 else q,r = div(u,v) g,s',t' = eGCD(v,r) s = t' t = s' - q return g |
Why this works
g = s' v + t' r assume the recursive call works (ind. hypothesis)
u = q v + r by the definition of division
u - q v = r rewriting the line above
g = s' v + t' (u - q v) substituting u - qv for r
g = s' v + t' u - t' q v expanding
g = t' u + (s' - t' q) v
--- -----------
s t
|