Efficient modular exponentiation algorithms in Python