class Exponentiation {

	public static BigInteger modPow(BigInteger base, BigInteger exponent, BigInteger modulus) {
		if (GMP_AVAILABLE) {
			if (USE_SECURE_MOD_POW) {
				return exponent.signum() < 0 // Gmp library can't handle negative exponents
						? modInverse(Gmp.modPowSecure(base, exponent.negate(), modulus), modulus)
						: Gmp.modPowSecure(base, exponent, modulus);
			} else {
				return exponent.signum() < 0 // Gmp library can't handle negative exponents
						? modInverse(Gmp.modPowInsecure(base, exponent.negate(), modulus), modulus)
						: Gmp.modPowInsecure(base, exponent, modulus);
			}
		} else {
			return base.modPow(exponent, modulus);
		}
	}

}