Category 9 — Cryptography / Security

Modular Exponentiation

Compute ab mod n using fast square-and-multiply with arbitrary-precision BigInt.

How to use this tool

  1. Enter the base, exponent, and divisor into Base (a), Exponent (b), and Modulus (n) — the result appears instantly as you type.
  2. Read the result panel: it shows the answer in Decimal and Hexadecimal, the number of decimal digits, and the compute time in milliseconds.
  3. Try RSA demo 1 or RSA demo 2 to load real RSA encrypt/decrypt values, or DH demo for a Diffie–Hellman key-exchange example.
  4. Press Copy to copy the decimal result to your clipboard.
  5. Edit any field to recompute — inputs must be non-negative integers (digits only).

Why this tool is helpful

Verify RSA encryption & decryption

RSA is built on m^e mod n and c^d mod n. Load the demos to see the classic 3233 textbook example compute correctly.

Check Diffie–Hellman shared secrets

Both parties in DH compute g^a mod p to arrive at the same shared key. Verify your own values match.

Cross-check crypto code

Compare your hand-rolled RSA, DH, or ElGamal implementation against the independent BigInt result to catch off-by-one or overflow bugs.

Explore number theory

Quickly test Fermat's little theorem, Euler's theorem, and modular inverses without writing a script.

Go beyond 64-bit limits

BigInt handles exponents with hundreds of digits that overflow plain number types, so real cryptographic exponents compute exactly.

Stay private

Everything runs in your browser. Your inputs and results are never uploaded, logged, or sent to a server.

FAQ

What does modular exponentiation compute?

It computes a^b mod n — the remainder when a raised to the power b is divided by n. For example, 7^256 mod 13 evaluates to 3.

How does it handle such huge powers so fast?

It uses the square-and-multiply (binary exponentiation) algorithm, which reduces the work from b multiplications down to roughly log2(b). The result is always reduced mod n at each step, keeping intermediate values small.

Why is the result always smaller than the modulus?

Because the result is a remainder after division by n, it always falls in the range 0 to n − 1.

Why do I get "integers only"?

This tool accepts non-negative whole numbers only. Negative signs, decimals, and thousands separators are rejected, since modular exponentiation is defined over integers.

Why does a modulus of zero show an error?

Computing mod 0 means dividing by zero, which is undefined. Use a modulus of at least 1; with n = 1 the result is always 0.

Can it handle numbers larger than 2^53?

Yes. It uses JavaScript's arbitrary-precision BigInt, so there is no 64-bit or double-precision limit — only your browser's memory.

Does any of my data leave my browser?

Never. All computation happens locally in JavaScript. Your inputs and results are not sent to, stored on, or logged by any server.