I have implemented an algorithm in Mathematica that uses PowerMod to find a modular inverse. I now need to implement this algorithm in C, and I've decided to use gmp and its function mpz_powm, which apparently does the same thing. The problem is, I'm not getting the same values. For instance, when run on Mathematica it gives:
PowerMod[30030, -1, 43] = 35
while mpz_pwm gives 16. And:
PowerMod[30030, -1, 71] = 8
whereas mpz_pwm gives 46. (I hope these are enough examples.) I have also tried various modular inverse algorithms I've managed to find online and they give different values too. I suspect, though, that Mathematica is right. Does anyone know what is happening here?