Exponentiation by squaring