b2KIT

Modular Arithmetic Calculator

Perform modular exponentiation, GCD, modular inverse, and Chinese Remainder Theorem calculations for cryptography.

Tested tool guide Tested browser tools Checked August 16, 2026

What Modular Arithmetic Calculator does, with a checked example

Four number-theory questions share this calculator: compute a^b modulo m, find gcd(a, b), solve a*x congruent to 1 modulo m, or combine simultaneous congruences with the Chinese Remainder Theorem. Each operation takes the corresponding integers, including residue-modulus pairs for CRT. These are exact calculations used in cryptographic arithmetic, not floating-point estimates. The common surprise is that a nonzero value does not automatically have an inverse: the value and modulus must have greatest common divisor 1.

Worked example

A concrete input and expected output from the current implementation.

Input

Operation: modular exponentiation; base = 7; exponent = 4; modulus = 13

Expected output

9

7^2 = 49, which leaves remainder 10 modulo 13. Therefore 7^4 is congruent to 10^2 = 100, and 100 = 7*13 + 9, so the requested residue is 9.

How the result is produced

1

Powers, divisors, and inverses

For modular exponentiation, the mathematical target is the residue of a^b after division by m; reducing intermediate powers does not change that final residue. Except for the input pair (0, 0), GCD identifies the greatest positive divisor shared by its two inputs; for (0, 0), no greatest positive common divisor exists. For an inverse, the target is an integer x for which a*x is congruent to 1 modulo m, and existence depends on gcd(a, m).

2

CRT solution classes

For CRT calculations, each residue-modulus pair states a condition of the form x is congruent to r modulo m. A solution must satisfy every condition at once. When the positive moduli are pairwise coprime, one residue class exists modulo their product. The representative shown is only one member of that class; adding or subtracting the combined modulus gives further valid integers.

Good uses

  • Checking a modular power in a small RSA encryption or decryption exercise.
  • Testing whether an RSA-style public exponent is coprime to a known totient, then finding its modular inverse for a worked key example.
  • Recombining independently calculated residues from coprime moduli in a hand-worked Chinese Remainder Theorem calculation.

Limits and checks

  • Modulus 0 is not valid for these congruence operations. Negative moduli and negative residues can be rewritten with a positive modulus, but equivalent representatives may look different, so compare congruence classes rather than the displayed integer alone.
  • A modular inverse is not ordinary reciprocal division. If gcd(value, modulus) is greater than 1, no inverse exists; an error or no-solution result must not be read as 0. An inverse of 0 never exists for a modulus greater than 1.
  • The simple CRT product rule requires pairwise coprime moduli. Non-coprime congruences can have no solution or a solution class whose period is the least common multiple, not the product. Do not assume a single representative is a unique integer solution.

Common questions

Why does a modular inverse sometimes not exist?

An inverse of a modulo m must make a*x leave remainder 1 when divided by m. This is possible exactly when gcd(a, m) = 1. For example, 6 has no inverse modulo 15 because gcd(6, 15) = 3; every product 6x is divisible by 3 and therefore cannot be congruent to 1 modulo 15.

Is the value returned by a CRT calculation the only solution?

No. A CRT result identifies a complete residue class. If the result is x congruent to 8 modulo 15, then 8, 23, 38, and every 8 + 15k for integer k represent the same class. Pairwise coprime input moduli guarantee uniqueness only modulo their product, not uniqueness among all integers.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools