Skip to main content

Modular Exponentiation Calculator (a^b mod m)

Compute a^b mod m with fast exponentiation and BigInt, plus modular inverse and step-by-step squaring, all in your browser

  • Runs locally
  • Category Developer & DevOps
  • Best for Formatting, validating, shrinking, or inspecting code-adjacent text.
Try:
a^b mod m
445
Modular inverse
4⁻¹ mod 497 = 373

Square-and-multiply on BigInt — exact for huge moduli. Nothing leaves your browser.

What this tool does

A modular exponentiation calculator that computes (base^exponent) mod modulus exactly, even when the numbers run hundreds of digits long. It uses the square-and-multiply algorithm (fast exponentiation), so an exponent like 65537 finishes in about 17 squarings instead of 65537 multiplications, and every intermediate value stays reduced mod m so it never blows up in size. Everything runs on JavaScript BigInt, which is why 4^13 mod 497 lands on 445 and 7^256 mod a 100-digit prime returns the right residue without rounding. The tool also gives you the modular inverse via the extended Euclidean algorithm, which lets it evaluate negative exponents whenever the base is coprime to the modulus, and an optional step view that prints each squaring so you can follow the bits of the exponent. This is the exact operation at the heart of RSA, Diffie-Hellman and the Miller-Rabin primality test. Inputs round-trip through the URL so a shared link reopens the same calculation, and one click copies the result. 100% client-side, nothing is uploaded.

Tool details

Input
Form fields
The page exposes text boxes, numeric controls, file pickers, or structured inputs depending on the tool.
Output
Live result + Copy
The result area focuses on usable output, with copy, download, or preview actions when supported.
Privacy
Browser-side processing
The main tool logic does not call an external API, so inputs normally stay in the current tab.
Save / share
Shareable URL state
Key settings are encoded in the URL so another person can reopen the same setup.
Performance budget
Initial JS <= 9 KB
No WASM budget is declared, keeping the tool quick to open on mobile.
Best fit
Developer & DevOps · Developer
Category and role tags drive related tools, internal links, and quick fit checks.

How to use

  1. 1. Input

    Paste or drop your content into the tool panel.

  2. 2. Process

    Click the button. All processing is local in your browser.

  3. 3. Copy / Download

    Copy the result or download to disk in one click.

How Modular Exponentiation Calculator fits into your work

Use it in the small gaps between coding, reviewing, debugging, and shipping.

Developer jobs

  • Formatting, validating, shrinking, or inspecting code-adjacent text.
  • Preparing snippets for documentation, tickets, commits, or handoff.
  • Checking a small payload quickly without switching tools.

Developer checks

  • Run irreversible transforms like minify or obfuscate on a copy.
  • Keep secrets out of pasted snippets unless the tool explicitly stays local.
  • Use your normal tests or linter before shipping transformed code.

Good next steps

These links move the current task into a more complete workflow.

  1. 1 Prime Factorization Calculator Break any integer into prime factors with exponent form, divisor count and full divisor list, exact BigInt math, browser-only Open
  2. 2 GCD & LCM Calculator GCD + LCM of any list of integers — Euclidean steps, prime factorization, prime-factor table — exact BigInt math, browser-only Open
  3. 3 Bitwise Calculator AND, OR, XOR, NOT and bit shifts on integers, with decimal, hex and binary side by side, all in your browser Open

Real-world use cases

  • Hand-verify an RSA encryption or decryption step

    You are learning RSA and want to confirm a textbook example by hand. With p, q, e and d chosen, encryption is c = m^e mod n and decryption is m = c^d mod n. Drop in the message as the base, the public exponent e as the exponent, and n as the modulus, and read c directly. Then feed c back with the private exponent d and watch the original message come out. Because everything is BigInt, a realistic 1024-bit n works exactly, not just the tiny toy moduli most homework examples are limited to.

  • Check a Diffie-Hellman key exchange by hand

    Diffie-Hellman has each party compute g^secret mod p. To verify a worked example, put g as the base, your secret exponent as the exponent, and the prime p as the modulus to get your public value. Then raise the other side's public value to your secret, also mod p, and confirm both sides land on the same shared key. The square-and-multiply view makes it obvious why the exchange is cheap to compute forward yet hard to reverse without the secret.

  • Debug a modPow implementation in your own code

    You wrote a fast-exponentiation routine in C, Python or Go and your test vectors disagree. Paste the same base, exponent and modulus here to get the known-good answer from a BigInt reference, then turn on the step view to compare your intermediate squarings against the tool's. A common bug is forgetting to reduce mod m after the multiply step, which only shows up on large inputs, and the step list pinpoints exactly where your values diverge.

  • Teach or study fast exponentiation in a number theory class

    When introducing square-and-multiply, the gap between b multiplications and log2(b) squarings is hard to feel from a formula. Set a small base and an exponent like 13 or 100, turn on the step view, and the bit-by-bit breakdown shows precisely which squares get multiplied in. Students can change the exponent and watch the step count grow with the number of bits, not with the size of the number, which is the whole insight the algorithm is built on.

Common pitfalls

  • Computing a^b first and then taking mod m. For any real cryptographic size this overflows or freezes, because a^b can have more digits than the universe has atoms. Always reduce mod m at every multiply, which is exactly what square-and-multiply does and what this tool does internally.

  • Expecting a negative exponent to always work. a^(-b) mod m only exists when the base is coprime to the modulus, because it needs the modular inverse. If gcd(base, m) is not 1 there is no inverse, so 4^(-1) mod 6 is undefined and the tool reports an error rather than inventing a value.

  • Passing a modulus of 0 or 1 without thinking. Modulus 0 is invalid because the remainder is undefined. Modulus 1 is valid but always returns 0, since every integer is congruent to 0 mod 1, so a^b mod 1 = 0 even for a^0, which can surprise you if you expected 1.

Privacy

Every step here is plain JavaScript BigInt math running in your browser tab. The base, exponent and modulus you type, and the result, never leave the page and are not logged anywhere. The one caveat is the shareable URL, which encodes your three inputs in the query string, so a link pasted into chat will record those numbers in the recipient server's access log. If you are checking a real private key or secret exponent, use the copy button and paste the text rather than sharing the URL.

FAQ

Tool combos

Folks in your role tend to reach for these alongside this tool.

Made by Toolora · 100% client-side · Updated 2026-05-29