public static int modPow(int base, final int exp, final int mod) {
        notNegativeCheck(exp);
        positiveCheck(mod);
        base = normalizeIntModulo(base, mod);
        if (mod == 1)
            return 0;
        if (base == 0)
            return ((exp == 0) ? 1 : 0);
        if ((base == 1) || (exp == 0))
            return 1;
        if (base == -1)
            return ((exp % 2 == 0) ? 1 : -1 + mod);
        if (exp == 1)
            return base;
                    
        final BigInteger bigBase = intToBigInteger(base);
        final BigInteger bigExp = intToBigInteger(exp);
        final BigInteger bigMod = intToBigInteger(mod);
        return bigBase.modPow(bigExp, bigMod).intValue();
    }