peterolson / BigInteger.js

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

Update type definition and README.md with isPrime's optional strict parameter #198

Closed silentsilas closed 4 years ago

silentsilas commented 4 years ago

I'm building an interactive RSA tool, and I just about finished the key generation for up to 4086-bit keys when I realized Safari has yet to implement BigInt. So, needless to say, I wished to thank you for this library/polyfill and contribute what little I can to it.

Also, is there an ELI5 for that strict parameter? I understand it changes how many integers it tests against, but I haven't a clue what GRH is, lol.

coveralls commented 4 years ago

Coverage Status

Coverage remained the same at 94.318% when pulling 317b6b136f9c3ca8772e17284836275ffcd78f12 on Poeticode:patch-1 into c012f0af01846b3de0d54fe0075f4c6e037fe412 on peterolson:master.

gardhr commented 4 years ago

Basically, isPrime(true) gives you a 100% certificate of primality based on proven mathematical theorems whereas the much more efficient isPrime(false) relies on the unproven-yet-widely-accepted-as-true GRH.

Incidentally, invoking isProbablePrime with the default parameters already tells you with something like 99.9% certainty whether or not a number is prime (and in a fraction of the time required for isPrime) so unless you just need cryptographically secure primes or what have you then isProbablePrime is the best option altogether.

silentsilas commented 4 years ago

Ah, that makes sense! We must have skimmed over GRH in my Intro to Crypto course. Thank you.

peterolson commented 4 years ago

Sorry for the long delay in merging, I must have overlooked it before.