Calculate modular exponentiation xy mod n instantly. Enter the base, the exponent and the modulus to obtain the remainder efficiently with the binary exponentiation algorithm.
Modular Exponentiation Calculator
How to use the calculator
- In the x (base) field, enter the base (an integer).
- In the y (exponent) field, enter the exponent (a non-negative integer).
- In the n (modulus) field, enter the modulus (a positive integer, n ≥ 1).
- Select Calculate. The value of xy mod n will appear in the Result field.
- To start a new calculation, select Clear.
What is modular exponentiation?
Modular exponentiation calculates the remainder when xy is divided by n:
xy mod n = r
where r is the remainder when xy is divided by n, with 0 ≤ r < n.
This operation is fundamental to number theory and public-key cryptography (including RSA), where extremely large powers must be evaluated efficiently.
Fast modular exponentiation
Computing xy directly becomes impractical for large exponents. The binary exponentiation algorithm solves the problem in O(log y) operations by repeatedly squaring the base:
- If y is even: xy = (xy/2)2
- If y is odd: xy = x × xy−1
The modulus is applied at every step, keeping intermediate values small.
Modular exponentiation examples
| x (base) | y (exponent) | n (modulus) | xy mod n |
|---|---|---|---|
| 2 | 10 | 7 | 2 |
| 3 | 4 | 5 | 1 |
| 5 | 3 | 13 | 8 |
| 7 | 0 | 10 | 1 |
| 2 | 100 | 1000000007 | 976371285 |
Frequently asked questions
What is modular exponentiation?
Modular exponentiation evaluates xy mod n: the remainder obtained when xy is divided by n. It is fundamental to cryptography and number theory.
How do I calculate xy mod n?
Enter the base x, exponent y, and modulus n, then select Calculate. The result is the remainder when xy is divided by n, computed with fast modular exponentiation.
Why is modular exponentiation used in cryptography?
Modular exponentiation underpins RSA and the Diffie–Hellman protocol. It is efficient in the forward direction but extremely hard to reverse through the discrete logarithm problem, a useful asymmetry for digital security.
What is 2¹⁰ mod 7?
2¹⁰ = 1024, and 1024 = 146 × 7 + 2. Therefore, 2¹⁰ mod 7 = 2.
What is the binary exponentiation algorithm?
It is an efficient method for calculating xy mod n by repeatedly halving the exponent. This reduces the number of operations from O(y) to O(log y), allowing enormous powers to be handled in a fraction of a second.
Related calculators and guides
