Modular Arithmetic
Introduction
Modular arithmetic is the arithmetic of remainders. Instead of working with all integers, we work with a finite set of remainders when dividing by a fixed modulus. This creates a cyclical number system where arithmetic "wraps around."
Modular arithmetic is fundamental in cryptography (RSA, Diffie-Hellman), computer science (hash functions, checksums), and pure mathematics (studying prime numbers, solving Diophantine equations). The familiar 12-hour clock is an everyday example of arithmetic modulo 12.
Congruence
We say
if
Examples:
Properties of Congruence
Congruence is an equivalence relation:
• Reflexive:
• Symmetric:
• Transitive:
Arithmetic Operations
If
We can add, subtract, and multiply congruences freely. Division is more delicate—we need multiplicative inverses.
Multiplicative Inverses
The multiplicative inverse of a modulo
An inverse exists if and only if
Example: Find
The Group ℤ/nℤ
The integers modulo
The units (elements with multiplicative inverses) form the group
Euler's Totient Function
For prime power:
Multiplicative property: If
General formula:
Fermat's Little Theorem
If
Equivalently, for any
This gives an easy way to compute inverses:
Euler's Theorem
Generalizes Fermat's Little Theorem. If
For prime
Chinese Remainder Theorem
If
has a unique solution modulo
This means
Linear Congruences
The equation
If solvable, there are exactly
Modular Exponentiation
Computing
• If
• If
This requires only
RSA Cryptography
RSA is a public-key encryption system based on modular arithmetic. Key generation:
Choose large primes
p andq computen=p*q Compute
ϕ(n)=(p−1)*(q−1) Choose
e coprime toϕ(n) findd≡e(−1)*(mod(ϕ(n)))
Public key:
Encryption:
Security relies on the difficulty of factoring
Primality Testing
Fermat's test: If
Passing the test doesn't guarantee primality (Carmichael numbers are exceptions). Miller-Rabin is a stronger probabilistic test used in practice.
Wilson's Theorem
This is a theoretical characterization of primes (computing factorials is too slow for practical primality testing).
Quadratic Residues
Euler's criterion:
Summary
Modular arithmetic works with remainders:
Euler's totient
RSA cryptography is built on modular exponentiation and the difficulty of factoring. Modular arithmetic is essential in computer science, cryptography, and number theory.