MODULAR-EXPONENTIATION ( a , b , n )
1 c ← 0
2 d ← 1
3 let < bkbk-1 ... b0 > be the binary representation of b .
4 for i = k down to 0
5 do c ← 2 c
6 d ← ( d · d ) mod n
7 if bi = 1
8 then c ← c + 1
9 d ← ( d · a ) mod n
10 return d
Here we note that the above program will run perfectly even if we remove the variable c altogether from the program. The variable c is retained to describe the loop invariant with which we establish the correctness of the above algorithm.