Modular Exponentiation Calculator
Compute base^exponent mod modulus using fast square-and-multiply exponentiation — the algorithm behind RSA and other public-key cryptography.
- 4^13 mod 497
- 445
How it works
This computes base^exponent mod modulus using square-and-multiply (binary exponentiation), the standard algorithm for this problem rather than raising base to exponent first and reducing afterward — that would produce a number far too large to represent exactly once the exponent gets even moderately large.
The exponent is repeatedly halved: at each step the base is squared (and reduced mod modulus immediately, keeping every intermediate value small), and if the current bit of the exponent is 1, that squared value is folded into the running result. This takes only about log₂(exponent) multiplications instead of exponent − 1 of them, which is what makes modular exponentiation practical even for the huge exponents used in real cryptographic keys.
A negative base is first normalized into the range [0, modulus) before the algorithm runs, so the result always matches the standard non-negative convention for a modular remainder.
FAQ
Why does this matter for cryptography?
RSA encryption and decryption, Diffie-Hellman key exchange, and many other public-key algorithms are built entirely on modular exponentiation with very large numbers (hundreds of digits). Square-and-multiply is what makes computing those results feasible in a reasonable amount of time — without it, even a single RSA operation would be computationally infeasible.
Why is there a safe-integer limit on the inputs?
This calculator runs on BigInt internally, which keeps every intermediate multiplication exact no matter how large the numbers get — but the inputs and final result still have to round-trip through JavaScript's Number type for display, and Number can only represent integers exactly up to 2^53 − 1 (Number.MAX_SAFE_INTEGER). Real cryptographic keys use numbers far beyond that range and need a dedicated big-integer library, not a simple web calculator.
Related calculators
- Percentage Calculator
- Quadratic Equation Solver
- GCD & LCM Calculator
- Circle Area & Circumference Calculator
- Right Triangle Calculator (Pythagorean Theorem)
- Ratio Simplifier
- Exponent & Root Calculator
- Oblique Triangle Solver (Law of Cosines)
- Distance, Midpoint & Slope Calculator
- Permutations & Combinations Calculator (nPr, nCr)
- Arithmetic & Geometric Sequence Calculator
- Regular Polygon Calculator
- Z-Score & Percentile Calculator
- Cubic Equation Solver
- Prime Factorization Calculator
- System of Linear Equations Solver (2 Equations)
- Half-Life Decay Calculator
- Vector Calculator (Dot Product, Cross Product, Angle)
- Ohm's Law Calculator
- Projectile Motion Calculator
- Matrix Determinant & Inverse Calculator (2x2 / 3x3)
- Ideal Gas Law Calculator (PV = nRT)
- Snell's Law Calculator (Refraction Angle)
- Wire Resistance Calculator
- Clock Angle Calculator
- Pythagorean Means Calculator (AM, GM, HM)
- Number Base Converter (Decimal to Binary, Octal, Hex)
- Dice Probability Calculator
- Pythagorean Triple Generator
- Binomial Probability Calculator
- Torque Calculator
- Law of Sines Triangle Solver
- Simple Pendulum Period Calculator
- Kinetic Energy Calculator
- Complex Number Calculator
- Circular Sector & Arc Length Calculator
- System of 3 Linear Equations Solver
- Reynolds Number Calculator
- Coulomb's Law Calculator
- Speed of Sound in Air Calculator
- Thin Lens Equation Calculator
- Centripetal Force Calculator
- Resistors in Series and Parallel Calculator
- RC Circuit Time Constant Calculator
- Escape Velocity Calculator
- Doppler Effect Calculator
- Birthday Paradox Calculator
- Ellipse Area, Circumference & Eccentricity Calculator
- Hyperbola Calculator
- Hooke's Law Spring Calculator
- Molarity (Molar Concentration) Calculator
- Momentum & Impulse Calculator
- Kepler's Third Law Orbital Period Calculator
- Triangle Area from Coordinates Calculator
- Beer-Lambert Law Absorbance Calculator
- LC Circuit Resonant Frequency Calculator