Modular Exponentiation Calculator
Calculate a^b mod n efficiently with the binary exponentiation algorithm. Enter the base, exponent and modulus for the result plus a step-by-step square-and-multiply breakdown, a binary decomposition visual 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 upgrading for ad-free browsing and more daily uses, or allowlist MiniWebtool.com and reload.
- Allow ads for MiniWebtool.com, then reload
- Or upgrade for ad-free browsing and higher daily limits
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.
Advanced Math Operations:
- Adjacency Matrix Calculator New
- Antilog Calculator
- Beta Function Calculator
- Binomial Coefficient Calculator
- Binomial Probability Distribution Calculator
- Bitwise Calculator Popular
- Boolean Algebra Simplifier New
- Central Limit Theorem Calculator
- Chinese Remainder Theorem Calculator
- Combination Calculator
- Complementary Error Function Calculator
- Complex Number Calculator
- Continued Fraction Calculator
- Derangement (Subfactorial) Calculator
- Dijkstra's Shortest Path Calculator
- Entropy Calculator
- Error Function Calculator
- Euler's Totient Function Calculator
- Exponential Decay Calculator
- Exponential Growth Calculator
- Exponential Integral Calculator
- Exponents Calculator
- Extended Euclidean Algorithm Calculator
- Factorial Calculator
- Gamma Function Calculator
- Golden Ratio Calculator
- Graph Coloring Calculator New
- Graph Degree Sequence Validator
- Group Theory Order Calculator New
- Half Life Calculator
- Hamiltonian Path Checker New
- Inclusion-Exclusion Calculator New
- Karnaugh Map (K-Map) Solver New
- Linear Programming Solver New
- Markov Chain Steady State Calculator
- Minimum Spanning Tree Calculator
- Modular Exponentiation Calculator New
- Modular Multiplicative Inverse Calculator
- Negative Binomial Distribution Calculator New
- Network Flow Calculator (Max Flow) New
- Percent Growth Rate Calculator Popular
- Permutation Calculator
- Permutations with Repetition Calculator New
- Pigeonhole Principle Calculator
- Planar Graph Checker New
- Poisson Distribution Calculator
- Polynomial Roots Calculator
- Primitive Root Calculator
- Probability Calculator
- Probability Distribution Calculator
- Proportion Calculator Popular
- Quadratic Formula Calculator
- Ring and Field Calculator New
- Rounding Calculator New
- Scientific Calculator
- Scientific Notation Calculator Popular
- Set Theory Calculator
- Significant Figures Calculator New
- Stable Marriage Problem Solver New
- Stirling Numbers Calculator
- Sum of Cubes Calculator
- Sum of Positive Integers Calculator
- Sum of Squares Calculator
- Topological Sort Calculator New
- Traveling Salesman Solver (TSP) New
- Truth Table Generator
- Venn Diagram Generator (3 Sets)