Modular Exponentiation Calculator
Calculate modular exponentiation a^b mod n efficiently using the binary exponentiation (fast power) algorithm. Enter the base, exponent, and modulus to get instant results with a step-by-step breakdown of the squaring-and-multiply method, binary decomposition visualization, and cryptographic context.
Your ad blocker is preventing us from showing ads
MiniWebtool is free because of ads. If this tool helped you, please support us by going Premium (ad‑free + faster tools), or allowlist MiniWebtool.com and reload.
- Allow ads for MiniWebtool.com, then reload
- Or upgrade to Premium (ad‑free)
About Modular Exponentiation Calculator
The Modular Exponentiation Calculator computes \(a^b \bmod n\) — raising a base \(a\) to an exponent \(b\) and taking the remainder when divided by modulus \(n\). It uses the binary exponentiation algorithm (also called fast power or exponentiation by squaring), which reduces the operation from \(O(b)\) multiplications to just \(O(\log b)\). This is the same algorithm used in real-world cryptographic implementations like RSA, Diffie-Hellman, and ElGamal.
Applications of Modular Exponentiation
How the Binary Exponentiation Algorithm Works
The key insight is that we can decompose any exponent into a sum of powers of 2 using its binary representation. For example, \(b = 13 = 1101_2 = 2^3 + 2^2 + 2^0\), so \(a^{13} = a^{8} \times a^{4} \times a^{1}\).
The algorithm processes the binary digits of the exponent from left to right:
Pseudocode
function modpow(base, exp, mod):
result = 1
base = base mod mod
while exp > 0:
if exp is odd: // bit is 1
result = (result × base) mod mod
exp = exp >> 1 // shift right (divide by 2)
base = (base × base) mod mod
return result
Key Formulas
| Property | Formula | Description |
|---|---|---|
| Modular Exponentiation | \(a^b \bmod n\) | Remainder of a^b divided by n |
| Fermat's Little Theorem | \(a^{p-1} \equiv 1 \pmod{p}\) | For prime p and gcd(a,p)=1 |
| Euler's Theorem | \(a^{\phi(n)} \equiv 1 \pmod{n}\) | For gcd(a,n)=1, where φ is Euler's totient |
| Binary Method Complexity | \(O(\log b)\) multiplications | At most 2·log₂(b) modular multiplications |
| RSA Encryption | \(c = m^e \bmod n\) | Encrypt message m with public key (e, n) |
| RSA Decryption | \(m = c^d \bmod n\) | Decrypt ciphertext c with private key d |
How to Use the Modular Exponentiation Calculator
- Enter the base (a): This is the number you want to raise to a power. It can be positive or negative. For example, enter 7 for computing 7^256 mod 13.
- Enter the exponent (b): This must be a non-negative integer. It represents the power. For cryptographic applications, this can be very large (the calculator supports up to 10^18).
- Enter the modulus (n): This must be a positive integer. It is the number you divide by to get the remainder. In RSA, this is typically the product of two large primes.
- Click Calculate: The calculator computes a^b mod n using binary exponentiation and shows the result instantly.
- Watch the animation: Press Play to watch the binary exponentiation algorithm execute step by step. Each bit of the exponent is processed in sequence, showing whether the algorithm squares, or squares and multiplies.
- Review the trace: The step-by-step table shows every intermediate computation, and the efficiency comparison shows how much faster binary exponentiation is versus naive repeated multiplication.
Why Binary Exponentiation is Fast
Consider computing \(2^{1000} \bmod 13\). The naive approach requires 999 multiplications. Binary exponentiation converts 1000 to binary (1111101000), which has 10 bits. It needs at most 9 squarings plus a few multiplies for each '1' bit — roughly 15 operations total. That is about 98.5% fewer operations. For cryptographic-scale exponents with hundreds of digits, the difference is astronomical: binary method takes thousands of operations where naive would require more operations than atoms in the universe.
FAQ
Reference this content, page, or tool as:
"Modular Exponentiation Calculator" at https://MiniWebtool.com/modular-exponentiation-calculator/ from MiniWebtool, https://MiniWebtool.com/
by miniwebtool team. Updated: 2026-04-16
You can also try our AI Math Solver GPT to solve your math problems through natural language question and answer.
Related MiniWebtools:
Advanced Math Operations:
- Antilog Calculator
- Beta Function Calculator
- Binomial Coefficient Calculator
- Binomial Probability Distribution Calculator
- Bitwise Calculator Featured
- Central Limit Theorem Calculator
- Combination Calculator
- Complementary Error Function Calculator
- Complex Number Calculator
- Entropy Calculator
- Error Function Calculator
- Exponential Decay Calculator
- Exponential Growth Calculator
- Exponential Integral Calculator
- Exponents Calculator
- Factorial Calculator
- Gamma Function Calculator
- Golden Ratio Calculator
- Half Life Calculator
- Percent Growth Rate Calculator Featured
- Permutation Calculator
- Poisson Distribution Calculator
- Polynomial Roots Calculator
- Probability Calculator
- Probability Distribution Calculator
- Proportion Calculator
- Quadratic Formula Calculator
- Scientific Calculator
- Scientific Notation Calculator
- Significant Figures Calculator New
- Sum of Cubes Calculator
- Sum of Positive Integers Calculator Featured
- Sum of Squares Calculator
- Truth Table Generator
- Set Theory Calculator
- Venn Diagram Generator (3 Sets)
- Chinese Remainder Theorem Calculator
- Euler's Totient Function Calculator
- Extended Euclidean Algorithm Calculator
- Modular Multiplicative Inverse Calculator
- Continued Fraction Calculator
- Dijkstra's Shortest Path Calculator
- Minimum Spanning Tree Calculator
- Graph Degree Sequence Validator
- Derangement (Subfactorial) Calculator
- Stirling Numbers Calculator
- Pigeonhole Principle Calculator
- Markov Chain Steady State Calculator
- Rounding Calculator New
- Negative Binomial Distribution Calculator New
- Permutations with Repetition Calculator New
- Modular Exponentiation Calculator New
- Primitive Root Calculator Featured
- Boolean Algebra Simplifier New
- Karnaugh Map (K-Map) Solver New
- Graph Coloring Calculator New
- Topological Sort Calculator New
- Adjacency Matrix Calculator New
- Inclusion-Exclusion Calculator New
- Linear Programming Solver New
- Traveling Salesman Solver (TSP) New
- Hamiltonian Path Checker New
- Planar Graph Checker New
- Network Flow Calculator (Max Flow) New
- Stable Marriage Problem Solver New
- Group Theory Order Calculator New
- Ring and Field Calculator New