Fast modular exponentiation for cryptography, math, and coding projects with confidence. Handles huge integers using optimized algorithms and optional big libraries for accuracy. See step breakdowns, history, and shareable links for reproducibility across browsers easily. Export clean tables in CSV and PDF formats instantly.
| # | Timestamp | Base (a) | Exponent (e) | Modulus (n) | Result | Engine | Time (ms) |
|---|
| Base (a) | Exponent (e) | Modulus (n) | Expected a^e mod n | Action |
|---|---|---|---|---|
| 2 | 10 | 1000 | 24 | |
| 7 | 256 | 13 | 9 | |
| 123456789 | 987654321 | 97 | 46 | |
| 5 | 117 | 19 | 1 | |
| 3 | 644 | 645 | 36 | |
| 10 | 1000 | 17 | 16 | |
| 999 | 12345 | 10000 | 4999 |
We compute a^e mod n using fast binary exponentiation. At each step, if the current exponent bit is one, we multiply the accumulator by the base. Each loop squares the base modulo n and halves the exponent.
result = 1
while e > 0:
if e is odd: result = (result * a) mod n
a = (a * a) mod n
e = floor(e / 2)
When available, the calculator uses high‑performance libraries for big integers, equivalent to computing powmod(a, e, n) safely for very large values.
a to power e and taking the remainder modulo n: compute a^e mod n efficiently without expanding to enormous intermediate numbers.a modulo n first, then raise to the absolute exponent.n; modulus must be greater than zero.Common real‑world contexts where a^e mod n is essential, including indicative parameter sizes.
| Context | Base (a) | Exponent (e) | Modulus (n) | Notes |
|---|---|---|---|---|
| RSA encryption | Message m as integer |
Public e = 65537 |
Composite, ~2048–4096 bits | Computes c = m^e mod n |
| RSA decryption | Cipher c |
Private d |
Same n as above |
Computes m = c^d mod n |
| Diffie–Hellman | Generator g |
Secret a or b |
Prime p, ~2048+ bits |
Shared key via g^{ab} mod p |
| Fermat test | Random a |
n-1 |
Candidate n |
Checks a^{n-1} ≡ 1 (mod n) |
| ElGamal / DSA | Generator g, message hash |
Private/random exponents | Prime p, 2048+ bits |
Core step in signing/verification |
Helpful facts to reason about outputs and to validate results.
| Property / Theorem | Statement | Implication |
|---|---|---|
| Modular reduction | a ≡ b (mod n) ⇒ a^e ≡ b^e (mod n) |
Reduce base first without changing result |
| Fermat’s little theorem | a^{p-1} ≡ 1 (mod p) for prime p, p ∤ a |
Exponent cycles mod primes |
| Euler’s theorem | a^{φ(n)} ≡ 1 (mod n) if gcd(a,n)=1 |
Use φ(n) to reduce huge exponents |
| Carmichael function | a^{λ(n)} ≡ 1 (mod n) for gcd(a,n)=1 |
Often smaller exponent than φ(n) |
| Binary exponentiation cost | ⌊log₂ e⌋+popcount(e) multiplications, ⌊log₂ e⌋ squarings |
Runtime grows with exponent bits |
| CRT speed‑up | For RSA, compute mod p and q then recombine |
~3–4× faster decryption |
Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.