Modular Arithmetic & Modulo Calculator

Calculate modulo, fast modular exponentiation (A^B mod M), and modular multiplicative inverse.

Understanding Modular Arithmetic & Congruences

Modular arithmetic (often called "clock arithmetic") deals with integers where numbers "wrap around" upon reaching a given modulus. It forms the mathematical backbone of modern cryptography, including RSA encryption and Diffie-Hellman key exchange.

Modular Multiplicative Inverse Definition

A × X ≡ 1 (mod M)

An inverse X exists if and only if A and M are coprime (i.e. GCF(A, M) = 1). It is found using the Extended Euclidean Algorithm.

Step-by-Step Worked Examples

Example: 7¹³ mod 19

Using fast modular exponentiation: 7¹³ mod 19 = 11. Furthermore, the modular inverse of 7 mod 19 is 11, because 7 × 11 = 77 = 4 × 19 + 1.

Frequently Asked Questions

Why does -5 mod 12 equal 7 in mathematics?

In mathematics, the modulo operation yields a positive remainder in [0, M−1]. Adding 12 to −5 wraps around to positive 7.

When does a modular inverse fail to exist?

A modular inverse fails to exist whenever GCF(A, M) > 1, because no multiple of A can differ from a multiple of M by 1.