Click New Example to start working through an example. Click on the steps of the algorithm to see the values of the variables in each step. First click on step 1. and then on the following steps in the order of execution.
New Example Restart Example
Algorithm. Fast exponentiation modulo m.
Input:an integer b and natural numbers n and m greater than 1
Output:bn mod m
  1. let a := 1
  2. let c := b
  3. repeat
    1. let r := n mod 2
    2. if r=1 then let a := (a ⋅ c) mod m
    3. let n := n div 2
    4. let c := (c ⋅ c) mod m
  4. until n = 0
  5. return a