a^b mod m by squaring and multiplying over the bits of b: about 2 log b multiplications instead of b.
This interactive visualization needs JavaScript.