1

I'm working on a RSA assignment. Since the numbers were getting pretty large is used the InfInt biginter library. Now, the problem I'm facing is, if the numbers are too big like 6-7 digit input, the exponention function is taking too much time.

InfInt modPow(InfInt base, InfInt exp, InfInt n)
{

base = base%n;

if (exp == 0)
    return 1;

else if (exp == 1)
    return base;

else if (exp%2 == 0)
    return modPow(base*base%n, exp/2, n);

else
    return base*modPow(base, exp-1, n)%n;
}

Is there anyway, I can increase the speed ? I have read the Euler's method and others, but can't understand much. Will be great if someone can explain how to quicken this function.

Thanks

Uli Köhler
  • 13,012
  • 16
  • 70
  • 120
rbk
  • 283
  • 2
  • 3
  • 16

0 Answers0