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.
random_primein the RSA module says it generates a random prime above 1 000 000, but it counts up from 1 000 000 and stops at the first prime, so it returns 1 000 003 every time. Thefirst_primeargument looks meant to skip a prime you already have, but the loop condition!is_prime(n) && n != first_primestops as soon asn == first_prime, sorandom_prime(1_000_003)hands back 1 000 003 again, and two calls give p == q.It changes the following:
It now draws random numbers between 1 000 000 and 2 000 000 until it finds a prime that isn't
first_prime. The doc comment says so and has a small example of getting the two primes of a key. I replaced the second of the two identicalrandom_primetests with one that checks the skipped prime never comes back, and one that checks 20 calls don't all return the same prime. Both fail on main and pass here.Trial division is still fine at this size. If the Miller-Rabin module from #261 goes in, this could use it later for bigger primes.