peterolson / BigInteger.js

An arbitrary length integer library for Javascript
The Unlicense
1.12k stars 187 forks source link

modPow behaving badly :( #55

Closed pmohanta closed 9 years ago

pmohanta commented 9 years ago

20^2010 mod 564782141 = 537103799(I hope so) but I am getting 536569496.

It may be I have not read the limitations of bigInteger.js very well but if it does not work I cannot use it.

Observed problem starts after mod length >=9. Again I am not even sure the trusted answer(537103799) which I have mentioned here is correct. But I have 2 answers from 2 sources.

Any help will be appreciated

peterolson commented 9 years ago

What are the sources for your answer? I can't confirm that they are correct. Wolfram|Alpha seems to agree with the BigInteger answer:

http://www.wolframalpha.com/input/?i=20%5E2010+mod+564782141&x=10&y=1

peterolson commented 9 years ago

I'm closing this since I can't confirm that there is any issue. If you have any additional information, feel free to comment.

pmohanta commented 9 years ago

Sorry for the late reply as I was trying a means to verify. OK here it goes. You are correct and the other source has issues. Here is the proof.

Key pairs: 4411,21379 modbase 565864183 So if x^4411 mod 565864183 = y Then y ^ 21379 mod 565864183 should be equal to x.

Tried with 20 with your code. 20 ^ 4411 mod 565864183 = 357089474 357089474 ^ 21379 mod 565864183 = 20.

Have a nice day. Thanks Palash

On Mon, Nov 2, 2015 at 5:22 PM, Peter Olson notifications@github.com wrote:

Closed #55 https://github.com/peterolson/BigInteger.js/issues/55.

— Reply to this email directly or view it on GitHub https://github.com/peterolson/BigInteger.js/issues/55#event-452689993.