Power Mod Calculator

Input a base, exponent, and modulus to get the result using the fast exponentiation algorithm.

Calculate Modular Exponentiation: \( a^b \bmod c \)

Result

What is Modular Exponentiation?

Modular exponentiation involves finding the result of raising a base to an exponent and then computing the remainder when divided by a modulus. It is represented as: \( a^b \bmod c \) Here: \( a \) is the base, \( b \) is the exponent, \( c \) is the modulus.

This operation is widely used in cryptography, computer science, and number theory to efficiently compute large powers while keeping results manageable.

How to Calculate Modular Exponentiation

Calculating \( a^b \bmod c \) directly by finding \( a^b \) and then taking the modulus is computationally impractical for large values of \( b \). Instead, the fast exponentiation algorithm or modular exponentiation algorithm is used. Steps of the Fast Exponentiation Algorithm:

  1. Convert the exponent \( b \) into its binary representation.
  2. Initialize the result as 1.
  3. Start from the least significant bit of \( b \): If the bit is 1, multiply the current result by the base and take modulus \( c \).
  4. Square the base and take modulus \( c \) after each iteration.
  5. Repeat the process for all bits in \( b \).
  6. The final result is \( a^b \bmod c \).

Examples

Example 1: Calculate \( 5^3 \bmod 13 \)

Solution:

Binary representation of 3: \( 3_{10} = 11_2 \).

Initialize: result = 1, base = 5, modulus = 13.

Process binary digits (right to left):

  • First bit (1): result = \( (1 \times 5) \bmod 13 = 5 \), base = \( (5 \times 5) \bmod 13 = 12 \).
  • Second bit (1): result = \( (5 \times 12) \bmod 13 = 8 \).

Result: \(5^3 \bmod 13 = 8\).

Example 2: Calculate \( 7^4 \bmod 10 \)

Solution:

Binary representation of 4: \( 4_{10} = 100_2 \).

Initialize: result = 1, base = 7, modulus = 10.

Process binary digits (right to left):

  • First bit (0): No change to result, base = \( (7 \times 7) \bmod 10 = 9 \).
  • Second bit (0): No change to result, base = \( (9 \times 9) \bmod 10 = 1 \).
  • Third bit (1): result = \( (1 \times 1) \bmod 10 = 1 \).

Result: \(7^4 \bmod 10 = 1\).

Example 3: Calculate \( 3^{10} \bmod 7 \)

Solution:

Binary representation of 10: \( 10_{10} = 1010_2 \).

Initialize: result = 1, base = 3, modulus = 7.

Process binary digits (right to left):

  • First bit (0): No change to result, base = \( (3 \times 3) \bmod 7 = 2 \).
  • Second bit (1): result = \( (1 \times 2) \bmod 7 = 2 \), base = \( (2 \times 2) \bmod 7 = 4 \).
  • Third bit (0): No change to result, base = \( (4 \times 4) \bmod 7 = 2 \).
  • Fourth bit (1): result = \( (2 \times 2) \bmod 7 = 4 \).

Result: \(3^{10} \bmod 7 = 4\).