Modular Exponentiation Calculator

Calculate base^exponent mod modulus instantly using the fast square-and-multiply algorithm, with a full step-by-step breakdown.

Use the Modular Exponentiation Calculator

Inputs

Quick Examples

Enter values and click Calculate

Copied!

Summary

This modular exponentiation calculator computes base^exponent mod modulus using the binary square-and-multiply (fast exponentiation) method. It supports arbitrarily large integers through JavaScript BigInt, making it suitable for cryptographic problems, RSA key verification, and number theory exercises. Enter any three non-negative integers to get the result and a detailed trace capped at the first 200 steps.

How it works

  1. Enter the base, exponent, and modulus in the input fields.
  2. Click "Calculate" (or press Enter) to run the algorithm.
  3. The calculator converts the exponent to binary and processes each bit.
  4. For each bit, the current value is squared and, if the bit is 1, multiplied by the base — all mod the modulus.
  5. The step-by-step trace table shows up to the first 200 intermediate results.
  6. The final result appears at the top alongside the total step count.

Use cases

  • Verify RSA encryption and decryption results by hand.
  • Check Diffie-Hellman key exchange intermediate values.
  • Solve discrete logarithm and modular arithmetic homework problems.
  • Validate Miller-Rabin primality test computations.
  • Explore Euler's theorem and Fermat's little theorem examples.
  • Debug cryptographic implementations during development.
  • Teaching aid for university number theory and cryptography courses.
  • Quick sanity-check for large-exponent modular arithmetic.

Frequently Asked Questions

Last updated: 2026-05-29 · Reviewed by Nham Vu