liveBook · Manning

Modulo arithmetic

As explained in Hacking Cryptography

Arithmetic in which values are identified according to their remainders modulo a specified integer.

Modulo arithmetic identifies values by their remainders after division by a specified modulus. Clock arithmetic gives the intuition: 10 plus 3 hours is 1 modulo 12. section 2.2.2

In a linear congruential generator, each state is updated as Xₙ₊₁ = (aXₙ + c) mod m. This reduction keeps outputs within the modulus and supports parameter-recovery attacks. section 2.2.2

Inverses and implementation hazards

The multiplicative inverse of 7 modulo 12 is 7 because 7 × 7 = 49 ≡ 1 mod 12. In Go, -16 % 7 returns -2 rather than 5, so code must normalize negative results. section 2.2.2

Equation 2.3
\[X_{n+1} = \left( a X_n + c \right)\bmod m \label{equation:lcg}\]

Use the recurrence equation to connect modular reduction with the state transition of a linear congruential generator. section 2.2.2

How Hacking Cryptography covers it

How deep it goes
Explains recurrence, inverses, negative remainders, and recovery equations, then stops short of broader modular-arithmetic theory.
Examples
Demonstrates clock wraparound, 7’s inverse modulo 12, Go’s negative remainder, and LCG parameter-recovery code.
What it assumes
Assumes integer arithmetic and clock-style wraparound while developing modular inverses explicitly.
What you can do after
Diagnose/debug with it by implementing modular state updates and handling inverses and negative remainders correctly.
How it connects
Connects modular arithmetic with linear congruential generators, pseudorandom number generators, modular multiplicative inverses, and greatest common divisors.

Also explained in

Compare how 3 books explain modulo arithmetic →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Hacking Cryptography. The section links point to the parts of the book it draws on.