Category 9 — Cryptography / Security
Compute ab mod n using fast square-and-multiply with arbitrary-precision BigInt.
Base (a), Exponent (b), and Modulus (n) — the result appears instantly as you type.Decimal and Hexadecimal, the number of decimal digits, and the compute time in milliseconds.RSA demo 1 or RSA demo 2 to load real RSA encrypt/decrypt values, or DH demo for a Diffie–Hellman key-exchange example.Copy to copy the decimal result to your clipboard.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.
Both parties in DH compute g^a mod p to arrive at the same shared key. Verify your own values match.
Compare your hand-rolled RSA, DH, or ElGamal implementation against the independent BigInt result to catch off-by-one or overflow bugs.
Quickly test Fermat's little theorem, Euler's theorem, and modular inverses without writing a script.
BigInt handles exponents with hundreds of digits that overflow plain number types, so real cryptographic exponents compute exactly.
Everything runs in your browser. Your inputs and results are never uploaded, logged, or sent to a server.
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.
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.
Because the result is a remainder after division by n, it always falls in the range 0 to n − 1.
This tool accepts non-negative whole numbers only. Negative signs, decimals, and thousands separators are rejected, since modular exponentiation is defined over integers.
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.
Yes. It uses JavaScript's arbitrary-precision BigInt, so there is no 64-bit or double-precision limit — only your browser's memory.
Never. All computation happens locally in JavaScript. Your inputs and results are not sent to, stored on, or logged by any server.