Understanding modular exponentiation

Modular exponentiation computes the remainder of a base raised to an exponent, divided by a modulus. It is written as ab mod n and is a core operation in cryptography — used in RSA, Diffie-Hellman key exchange, and digital signatures.

For example, 310 mod 7. Computing 310 = 59049, then 59049 mod 7 = 4. The binary method achieves this efficiently by processing the exponent's bits rather than performing all 10 multiplications directly.

The binary (square-and-multiply) method works by scanning the exponent's binary representation from least significant to most significant bit, squaring the base at each step, and accumulating the result only when the current bit is 1.

Input tips

  • Enter non-negative integers for base and exponent.
  • Modulus must be a positive integer.
  • Use Calculate to stage your inputs before seeing the step-by-step breakdown.
  • The result shows the final remainder and each binary step.
  • Reset returns to example values so you can experiment.