Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR closes #92
It changes the following:
Adds a
primalitymodule with Miller-Rabin.is_primeis deterministic for everyu64, by testing the first twelve primes as bases, which is known to be enough below 2^64.miller_rabinis the probabilistic version with a chosen number of random bases, andrandom_prime(bits, rng)returns a random prime with exactly that many bits.mod_powworks inu128so the squarings can't overflow. The README walks from the Fermat test and Carmichael numbers to why Miller-Rabin's square root check catches them, and both are in the book summary and the main README list.Tests compare both versions against trial division for every n below 20 000, check Carmichael numbers and strong pseudoprimes for the smaller base sets (2047, 3 215 031 751, 3 825 123 056 546 413 051 and so on), some large primes and composites near 2^64, and that
random_primereturns the right bit length from 2 to 64 bits.I didn't hook it into RSA here so this stays one thing. AKS from the issue could come later as a slower but deterministic comparison.