Modular Exponentiation Calculator
Enter base, exponent, and modulus to compute a^b mod m with step-by-step square-and-multiply work shown.
Use the Modular Exponentiation Calculator
Inputs
Quick examples
Result
210 mod 1000
Answer
24
Square-and-Multiply Steps
MSB first| Step | Bit | Operation | Running result |
|---|
How square-and-multiply works
Convert the exponent to binary. Start with result = 1. For each bit from most-significant to least-significant: always square the result mod m; if the bit is 1, also multiply by the base mod m. This keeps numbers small at every step and runs in O(log b) multiplications.
Summary
This tool computes a^b mod m using the square-and-multiply (binary exponentiation) algorithm — the same method used inside RSA and Diffie-Hellman. Enter any positive integers for base, exponent, and modulus, and the calculator returns the result instantly while showing every intermediate squaring and multiplication step so you can follow the algorithm exactly.
How it works
- Enter the base (a), exponent (b), and modulus (m) in the input fields.
- The calculator converts the exponent to binary.
- It iterates each bit using square-and-multiply: square the running result, then multiply by the base when the bit is 1.
- Every intermediate step is shown so you can follow the algorithm.
- The final result is the value of a^b mod m.
Use cases
- Verify RSA encryption/decryption steps by hand.
- Understand Diffie-Hellman public key derivation.
- Check modular exponentiation homework problems.
- Learn the square-and-multiply algorithm for cryptography courses.
- Debug custom RSA or ElGamal implementations.
- Quickly compute large power-mod values without a full CAS tool.