Often for a powermod calculation it's fast enough to compute by squaring while considering the exponent in binary. I explain it here (post #7).
You might also like to compare with this Wikipedia article, which I found a bit hard to follow the last time I read it.
Modular exponentiation - Wikipedia, the free encyclopedia
For power towers, see this example (involving both totient and CRT - Chinese Remainder Theorem)