About This Calculator
-
What is this calculator for?
-
Can I embed this on my website?
-
How does modular exponentiation work?
What is this calculator for?
This calculator performs modular exponentiation. It calculates the result of a base number raised to an exponent, then divided by a modulus, returning the remainder.
Can I embed this on my website?
Yes, you can embed this calculator on your website. Here's the embed code:
<iframe width="415" height="220" src="http://www.a-calculator.com/modular-exponentiation/embed.html" frameborder="0" allowtransparency="true"></iframe>
Modular exponentiation is the operation of finding the remainder when a base number is raised to an exponent, then divided by a modulus. It is efficiently computed using the "Square-and-Multiply" algorithm, also known as "Exponentiation by Squaring". Here's how the algorithm works:
- Initialization: Set the result \(r = 1\) (the identity element for multiplication).
- Binary Representation: Express the exponent \(n\) in binary form.
- Iteration: For each bit in the binary representation of \(n\) (starting from the leftmost bit):
- Square: Square the current value of \(r\) and take the remainder modulo \(m\), i.e., \(r = (r^2) \mod m\).
- Multiply (if needed): If the current bit in the binary representation of \(n\) is 1, multiply \(r\) by \(a\) and take the remainder modulo \(m\), i.e., \(r = (r \cdot a) \mod m\).
- Result: After processing all bits, \(r\) will contain \(a^n \mod m\).
For example, to calculate \(3^{13} \mod 7\):
- Initialize \(r = 1\).
- The binary representation of \(13\) is \(1101\).
- Iterate through the bits of \(13\):
- Bit \(1\): Square \(r = 1^2 = 1\), Multiply \(r = 1 \cdot 3 = 3\).
- Bit \(1\): Square \(r = 3^2 = 9 \equiv 2 \mod 7\), Multiply \(r = 2 \cdot 3 = 6\).
- Bit \(0\): Square \(r = 6^2 = 36 \equiv 1 \mod 7\).
- Bit \(1\): Square \(r = 1^2 = 1\), Multiply \(r = 1 \cdot 3 = 3\).
- The result is \(3^{13} \mod 7 = 3\).