Modular Exponentiation Calculator

Calculate a^b mod m using fast exponentiation. Essential for cryptography and number theory.

Input

Common examples:

3^13 mod 7

3

Binary Representation of Exponent

13 = (1101)₂

4 bits

Euler's Totient

φ(7) = 6

If gcd(3, 7) = 1, then 3^6 ≡ 1 (mod 7)

Power Table

3^133^223^363^443^553^613^733^823^963^1043^1153^1213^133

Square-and-Multiply Steps

result = 1 × 3 mod 7 = 3
base = 3² mod 7 = 2
base = 2² mod 7 = 4
result = 3 × 4 mod 7 = 5
base = 4² mod 7 = 2
result = 5 × 2 mod 7 = 3

Square-and-Multiply Algorithm

How It Works

Instead of multiplying b by itself e times, we use the binary representation of e. For each bit, we square the base. For each 1-bit, we also multiply into the result.

Complexity

Time: O(log e) multiplications instead of O(e). Critical for cryptography where e can have hundreds of digits.