Modular Exponentiation Calculator
Compute base raised to an exponent modulo m by square-and-multiply, exact for integers of any practical length.
Modular Exponentiation Calculator
Compute base raised to an exponent modulo m by square-and-multiply, exact for integers of any practical length.
What the page prints, and what it refuses
Every figure is printed with the rule or formula that produced it, and any numerical tolerance is stated on the result rather than implied. The page refuses an input the formula does not define and names the value it read; it prints no answer it cannot support.
The calculation runs entirely in this browser tab; nothing is uploaded.
The page computes base^exponent mod m without ever forming the huge power. 7^560 mod 561 is 1, and the answer arrives after ten squaring steps rather than 560 multiplications.
Every intermediate product is reduced modulo m, so the numbers stay small and exact. The exponent is read as BigInt, which means 2^1000 mod 1000000007 is answered exactly.
Square-and-multiply
Write the exponent in binary. Starting from 1, square the running value for each bit and multiply by the base when the bit is 1, reducing modulo m after every step. The result is congruent to the full power.
A negative exponent is refused, because it requires a modular inverse that exists only when the base is coprime with the modulus; the modular inverse page answers that separate case.
How to use Modular Exponentiation Calculator
Enter the base, the exponent and a positive modulus, then press Run.
The result line gives the residue, followed by the equation, the reduced base and the exponent's bit length.
What to Expect
Best for
- Computing a large modular power exactly
- Checking a Miller–Rabin step
- Seeing why the power never overflows
Not ideal for
- A negative exponent, which needs a modular inverse
- A modulus of zero or below
- An exponent so large that printing its binary length is noise
What this tool keeps
- Base, exponent and modulus exactly
What may need cleanup
- Nothing: the residue is a final integer
Common errors
- A zero modulus is refused
- A negative exponent is refused with the inverse reason
Example use cases
- Evaluate 7^560 mod 561
- Check 2^1000 mod 1000000007
- Compute a Diffie–Hellman step
Sample input
base = 7, exponent = 560, modulus = 561
Sample output
7^560 mod 561 = 1, after 10 exponent bits
Who this is for
- Cryptography students
- Programmers testing a modular power
Frequently asked questions
Why is the answer 1?
561 is a Carmichael number, and 7 is coprime with it, so every coprime base satisfies a^560 ≡ 1. The page computes the congruence rather than asserting the theorem.
Can the base be negative?
Yes. The page reduces it modulo m first, so −3 mod 7 is 4 and the power proceeds from there.
Why is a negative exponent refused?
A negative exponent means a modular inverse, which exists only for a coprime base. That is a different calculation with its own page, so this one refuses instead of guessing.
Build custom tools for your store
Join the SDK program to create useful ecommerce utilities for your store.