Modular Exponentiation Calculator

Enter base, exponent, and modulus to compute a^b mod m with step-by-step square-and-multiply work shown.

Inputs

Quick examples

Result

210 mod 1000

Answer

24

Exponent bits: 1010 Steps: 4

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.

Copied!

Summary

Enter base, exponent, and modulus to compute a^b mod m with step-by-step square-and-multiply work shown.

How it works

  1. Enter the base (a), exponent (b), and modulus (m) in the input fields.
  2. The calculator converts the exponent to binary.
  3. It iterates each bit using square-and-multiply: square the running result, then multiply by the base when the bit is 1.
  4. Every intermediate step is shown so you can follow the algorithm.
  5. 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.

Frequently Asked Questions

Last updated: 2026-07-08 · Reviewed by Nham Vu