I want to calculate ab mod n for use in RSA decryption. My code (below) returns incorrect answers. What is wrong with it?
unsigned long i
Usually it's something like this:
while (b) { if (b % 2) { res = (res * a) % n; } a = (a * a) % n; b /= 2; } return res;