Modular Arithmetic for Cryptography
The integers, but wrapped around.
The algebra behind “undo”.
The workhorse of modular arithmetic.
\[ \begin{aligned} &\textbf{Forward pass (Euclidean algorithm):} \\ &\quad 3120 = 183 \times 17 + 9 \\ &\quad 17 = 1 \times 9 + 8 \\ &\quad 9 = 1 \times 8 + 1 \\ &\quad 8 = 8 \times 1 + 0 \\[6pt] &\textbf{Back-substitution:} \\ &\quad 1 = 9 - 1 \times 8 \\ &\quad 1 = 9 - 1 \times (17 - 1 \times 9) = 2 \times 9 - 1 \times 17 \\ &\quad 1 = 2 \times (3120 - 183 \times 17) - 1 \times 17 = 2 \times 3120 - 367 \times 17 \\[6pt] &\textbf{Result: } 17 \times (-367) \equiv 1 \pmod{3120} \\ &\quad d = -367 \equiv 2753 \pmod{3120} \end{aligned} \]
When division is possible, and why RSA works.
Making \(x^e \bmod n\) fast.
The algebra behind Diffie-Hellman.
Decomposing \(\mathbb{Z}_n\) when \(n\) factors.
Connecting the algebra to the crypto.
| Notation | Meaning | Used in |
|---|---|---|
| \(\mathbb{Z}_n\) | Integers \(\{0, \ldots, n-1\}\) with arithmetic mod \(n\) | RSA |
| \(\mathbb{Z}_n^*\) | Invertible elements of \(\mathbb{Z}_n\) | RSA, DH |
| \(\mathbb{Z}_p^*\) | \(\{1, \ldots, p-1\}\) for prime \(p\) | DH |
| \(\phi(n)\) | Euler’s totient: \(\lvert\mathbb{Z}_n^*\rvert\) | RSA correctness |
| \(\gcd(a, b)\) | Greatest common divisor | RSA keygen |
| \(a^{-1} \bmod n\) | Modular inverse via extended Euclidean | RSA \(d\) |
| \(\text{ord}(g)\) | Smallest \(d\) with \(g^d \equiv 1\) | DH subgroups |
| \(\mathbb{G}\) | Prime-order subgroup of \(\mathbb{Z}_p^*\) | DH protocol |