Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(458)

Unified Diff: src/pkg/big/nat.go

Issue 252041: code review 252041: big: fix mistakes with probablyPrime (Closed)
Patch Set: code review 252041: big: fix mistakes with probablyPrime Created 15 years ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pkg/big/int_test.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/big/nat.go
===================================================================
--- a/src/pkg/big/nat.go
+++ b/src/pkg/big/nat.go
@@ -586,6 +586,7 @@
q = makeN(nil, len(n)-zeroWords, false)
shiftRight(q, n[zeroWords:], x)
+ q = normN(q)
k = Word(_W*zeroWords + x)
return
@@ -705,7 +706,7 @@
var bigOne = []Word{1}
var bigTwo = []Word{2}
-// ProbablyPrime performs reps Miller-Rabin tests to check whether n is prime.
+// probablyPrime performs reps Miller-Rabin tests to check whether n is prime.
// If it returns true, n is prime with probability 1 - 1/4^reps.
// If it returns false, n is not prime.
func probablyPrime(n []Word, reps int) bool {
@@ -714,6 +715,10 @@
}
if len(n) == 1 {
+ if n[0] < 2 {
+ return false
+ }
+
if n[0]%2 == 0 {
return n[0] == 2
}
@@ -761,7 +766,7 @@
NextRandom:
for i := 0; i < reps; i++ {
x = randomN(x, rand, nm3, nm3Len)
- addNN(x, x, bigTwo)
+ x = addNN(x, x, bigTwo)
y = expNNN(y, x, q, n)
if cmpNN(y, bigOne) == 0 || cmpNN(y, nm1) == 0 {
continue
« no previous file with comments | « src/pkg/big/int_test.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b