0

Hi i'm trying to convert the below calculation to be used with bigint. I have converted it as per second code snippet and it runs with no errors but it doesn't return the same result. any ideas which bit i've converted wrongly?

while (exponent > 0)
    {
        int current_bit = exponent % 2;
        if (current_bit == 1)
          //  System.out.println("A" + result);
            result = (result * base) % modulus;
        //System.out.println("B" + result);
            exponent = exponent / 2;
        base = (base * base) % modulus;
       // System.out.println("C" + result);

    }
    return result;




    while (exponent.compareTo(BigInteger.valueOf(0)) == 1)
    {
        BigInteger current_bit = exponent.mod(BigInteger.valueOf(2));
       // System.out.println(exponent);
        if (current_bit == BigInteger.valueOf(1));
            //System.out.println("A" + result);
            result = (result.multiply(base)).remainder(modulus);
        //System.out.println("B" + result);
        exponent = exponent.divide(BigInteger.valueOf(2));
        base = (base.multiply(base)).remainder(modulus);
        //System.out.println("C" + result);
    }

    return result;

0 Answers0