Arithmetic That Wraps

A 12-hour clock does not count past 12. Five hours after 9 o’clock is 2 o’clock, not 14. That everyday collapse is the whole idea of modular arithmetic, “a system of arithmetic operations for integers” where numbers “wrap around” when reaching or exceeding a certain value, called the modulus. Wikipedia gives exactly this picture: on a clock modulo 12, “13 is congruent to 1 modulo 12.” Number theory is the study of the integers under divisibility and this wrapping, and it is the least optional branch of math for anyone doing cryptography.

Note

The payload: reducing modulo throws away magnitude and keeps only the remainder, folding infinitely many integers into residue classes. That deliberate loss of information is the source of cryptographic hardness. Forward operations (multiply two primes, exponentiate mod ) stay cheap; inverting them (factor the product, take a discrete logarithm) does not. The asymmetry is manufactured by working inside a finite ring where the answer no longer reveals how big the inputs were.

Divisibility and the GCD

divides (written ) when is an exact integer multiple of . The greatest common divisor is “the largest number that divides them both without a remainder.” Two integers whose gcd is are coprime, and coprimality is the precondition for a number to have a multiplicative inverse modulo .

Euclid’s algorithm computes the gcd without factoring either number, using one structural fact: “the greatest common divisor of two numbers does not change if the larger number is replaced by its difference with the smaller number.” Replace subtraction with remainder and each step shrinks the pair fast, so falls out in steps. The extended form additionally returns the Bézout coefficients with , which is how you actually compute a modular inverse.

Congruence

means divides , that is, and leave the same remainder on division by . Congruence is a equivalence relation: it is reflexive, symmetric, and transitive, so it carves the integers into disjoint residue classes . Addition and multiplication respect these classes, so you can reduce at any point in a computation and get the same answer, which is what keeps modular exponentiation from ever handling astronomically large intermediate values.

Primes

A prime is “a natural number greater than 1 that is not a product of two smaller natural numbers.” Primes are the multiplicative atoms of the integers: the fundamental theorem of arithmetic says “every natural number greater than 1 is either a prime itself or can be factorized as a product of primes that is unique up to their order.” Unique factorization is why “factor this number” is a well-posed and, for large semiprimes, brutally expensive question. Generating primes and testing primality are their own algorithmic topics.

Why Cryptography Sits On This

Modular arithmetic “directly underpins public key systems such as RSA and Diffie-Hellman.” RSA picks two large primes , publishes , and relies on the gap between multiplying them (trivial) and recovering them from (no known efficient method). The public and private exponents are modular inverses found with the extended Euclidean algorithm. Break the factoring problem and RSA falls; that single number-theoretic assumption is load-bearing for much of the internet’s transport security.

Example

Euclid on . Repeatedly replace the pair with (divisor, remainder): The last nonzero remainder is , so . No factoring of either number was needed, and the same three lines would run just as fast on 300-digit inputs.

Warning

“Coprime modulo ” is what makes inverses exist, not primality of itself. has an inverse mod exactly when . When is prime every nonzero residue is invertible (a field), which is why prime moduli are convenient, but the underlying requirement is always coprimality.

Sources