Modular exponentiation is the workhorse of public-key cryptography: RSA encryption, Diffie–Hellman key exchange and primality tests all compute huge powers modulo n. Computing xʸ first and then reducing would be impossible for 300-digit numbers.
How to use the Power Mod Calculator
- Base x
- Exponent y
- Modulus n
Everything is calculated in your browser, so results appear instantly and nothing you type is sent to a server.
How it works
The exponent is read in binary. At each bit the running base is squared modulo n, and when the bit is 1 the result is multiplied by the base. Exact BigInt arithmetic is used.
Formula
c = xʸ mod n, 0 ≤ c < n
Worked example
Inputs: Base x: 4; Exponent y: 13; Modulus n: 497.
Results: xʸ mod n = 445; Equation = 4¹³ mod 497 = 445; Square-and-multiply steps = Square-and-multiply (exponent in binary 1101):
bit 1: result = result × 4 mod 497 = 4
bit 0: skip
bit 1: result = result × 256 mod 497 = 30
bit 1: result = result × 429 mod 497 = 445.
Key terms
- Modular exponentiation
- Computing powers modulo n.
Frequently asked questions
What is 4¹³ mod 497?
445.
Why not compute 4¹³ first?
For large exponents the power has millions of digits; reducing at every step keeps numbers small.
What is Euler's theorem?
If gcd(x, n) = 1, x^φ(n) ≡ 1 (mod n), which can shorten exponents.
Can the exponent be negative?
Only with a modular inverse; this calculator needs y ≥ 0.