Modular inverse and modular power calculation and application