Modular arithmetic
Modular arithmetic is arithmetic in which integers are treated as equivalent when they differ by a multiple of a specified modulus.
Hacking Cryptography
Arithmetic in which values are identified according to their remainders modulo a specified integer.
- How it is used
- Uses modular reduction to implement linear congruential generator state transitions and recover their hidden parameters.
- 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 you can do after
- Diagnose/debug with it by implementing modular state updates and handling inverses and negative remainders correctly.
Real-World Cryptography
Modular arithmetic is arithmetic in which values are identified according to their remainders after division by a fixed modulus.
- How it is used
- Uses wrapped arithmetic and modular multiplication as foundations for Diffie–Hellman key exchange.
- How deep it goes
- Defines remainders, demonstrates multiplication and inverses, and connects the operation to multiplicative groups.
- Examples
- Uses a clock analogy, division by 5, and the product 3 × 2 modulo 5.
- What you can do after
- Apply modular reduction to simple divisions and multiplications, and identify multiplicative inverses modulo 5.
Read how Real-World Cryptography explains modular arithmetic →
Grokking Data Structures
Modular arithmetic is arithmetic in which values are considered equivalent when they have the same remainder under a specified modulus.
- How it is used
- Uses remainders to map virtual circular-queue positions back to valid array indexes.
- How deep it goes
- Defines remainders through an eight-element array example and stops short of broader mathematical treatment.
- Examples
- Uses 8 % 8 = 0, 9 % 8 = 1, and virtual index 8 wrapping to array index 0.
- What you can do after
- Apply it via the modulo operator to convert virtual circular-queue indexes into safe array positions.
Read how Grokking Data Structures explains modular arithmetic →
Also covered in
Related concepts
- dataset splitused by · A dataset split is the division of a dataset into distinct subsets assigned different purposes, such as training, validation, or evaluation.
- size_timplemented by · size_t is an unsigned integer type in C and C++ used to represent object sizes and related counts.
- integer wraparoundimplemented by · Integer wraparound is arithmetic behavior in which an out-of-range fixed-width integer result cycles or is reduced modulo the type’s representable range.
- unsigned integerimplemented by · An unsigned integer is an integer type or representation whose values are nonnegative.
- elliptic curve point additionused by · Elliptic-curve point addition combines two curve points according to the curve's group law to produce another curve point.
Questions about modular arithmetic
What is modular arithmetic?
Modular arithmetic is arithmetic in which integers are treated as equivalent when they differ by a multiple of a specified modulus.
Which Manning books explain modular arithmetic?
Hacking Cryptography, Real-World Cryptography and Grokking Data Structures.
What is the difference between modular arithmetic and polynomial arithmetic?
Modular arithmetic is arithmetic in which integers are treated as equivalent when they differ by a multiple of a specified modulus. Polynomial arithmetic is computation with polynomials using operations such as addition, multiplication, division, and reduction.
What is modular arithmetic also called?
Modular arithmetic is also called modulo.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


