Perform modular arithmetic operations: addition, subtraction, multiplication, exponentiation, and modular inverse. Includes GCD, extended Euclidean algorithm, and RSA examples.
The Modular Arithmetic Calculator performs the remainder-based operations used in cryptography, number theory, and algorithm design. You can evaluate a mod n, modular addition, subtraction, multiplication, exponentiation, and modular inverses without hand-running the Euclidean algorithm. It is a practical way to turn abstract congruence rules into direct calculations you can verify immediately. That is especially useful when a modular step appears inside code, proofs, or cryptography exercises and you want to confirm it quickly.
Modular arithmetic groups integers by their remainder after division. The statement "17 ≡ 5 (mod 12)" means 17 and 5 leave the same remainder when divided by 12, just like 12-hour clock arithmetic. That simple idea is the basis for RSA, checksums, pseudorandom generators, and many competitive-programming techniques.
Enter any operation and the tool returns the result together with the intermediate steps that matter: GCD, coprimality, inverse existence, and repeated-squaring reductions. That makes it useful both for verifying homework and for checking real implementation logic.
Use it to verify congruences, modular inverses, and fast exponentiation before you commit the result to code, coursework, or a cryptography exercise. It is much faster than working through repeated squaring and Euclid steps by hand. That makes it useful when you want the numeric result and the modular logic to stay aligned.
a mod n = a - n × ⌊a/n⌋. (a + b) mod n = ((a mod n) + (b mod n)) mod n. (a × b) mod n = ((a mod n) × (b mod n)) mod n. a^b mod n uses repeated squaring. Modular inverse: a⁻¹ mod n exists iff gcd(a,n) = 1.
Result: 7^256 mod 13 = 9
Computing 7^256 mod 13 using repeated squaring: 7^1=7, 7^2=49≡10, 7^4≡100≡9, 7^8≡81≡3, 7^16≡9... Final result: 7^256 mod 13 = 9. Direct computation of 7^256 would be impossibly large, but modular exponentiation handles it easily.
Working modulo n means every integer is represented by one of the residues 0 through n-1. Two integers are congruent when their difference is divisible by n, so they behave the same way inside modular calculations. That lets you replace large intermediate values with smaller remainders without changing the final answer.
Large powers are usually evaluated with repeated squaring: square, reduce modulo n, and keep going. That turns an enormous expression like a^b mod n into a short sequence of manageable multiplications. Modular inverses come from the extended Euclidean algorithm; they exist only when the base and modulus are coprime.
Cryptography is the best-known use case, but modular arithmetic also appears in hash tables, cyclic buffers, scheduling systems, and contest algorithms. When you can inspect the GCD, inverse, and reduction steps in one place, it is much easier to catch a wrong modulus or an invalid inverse before it propagates.
Modular arithmetic is a system where numbers "wrap around" after reaching a certain modulus. It's like clock arithmetic: 10 + 5 = 3 on a 12-hour clock. Formally, a ≡ b (mod n) means n divides (a-b).
The modular inverse of a modulo n is a number x such that a×x ≡ 1 (mod n). It exists if and only if gcd(a,n) = 1 (they are coprime). For example, 3⁻¹ mod 7 = 5 because 3×5 = 15 ≡ 1 (mod 7).
RSA encryption: C = M^e mod n. RSA decryption: M = C^d mod n. Where e×d ≡ 1 (mod φ(n)). The security relies on the difficulty of factoring n = p×q into its prime factors to find d from e.
Computing a^b mod n efficiently using repeated squaring. Instead of computing the huge number a^b then taking mod, we take mod at each step, keeping numbers small. This runs in O(log b) multiplications.
gcd(a,n) determines whether a has a modular inverse (only when gcd=1), whether the linear congruence ax≡b (mod n) has solutions, and what the extended Euclidean algorithm will return. Checking it first prevents impossible inverse requests and impossible congruence setups.
φ(n) counts integers from 1 to n that are coprime with n. For prime p: φ(p)=p-1. For n=pq: φ(n)=(p-1)(q-1). Euler's theorem: a^φ(n) ≡ 1 (mod n) when gcd(a,n)=1. This is foundational to RSA.