+2007-07-05 Sebastien Pouliot <sebastien@ximian.com>
+
+ * PrimalityTests.cs: Added Test method that select which algorithm,
+ SPP or RabinMillerTest, to use based on the prime-candidate size.
+ Removed previous workaround (as this is both a workaround and a good
+ fix ;-).
+
2007-07-05 Sebastien Pouliot <sebastien@ximian.com>
* PrimalityTests.cs: Rewritten RabinMillerTest to be closer to the
}
}
+ public static bool Test (BigInteger n, ConfidenceFactor confidence)
+ {
+ // Rabin-Miller fails with smaller primes (at least with our BigInteger code)
+ if (n.BitCount () < 100)
+ return SmallPrimeSppTest (n, confidence);
+ else
+ return RabinMillerTest (n, confidence);
+ }
+
/// <summary>
/// Probabilistic prime test based on Rabin-Miller's test
/// </summary>
// Applying optimization from HAC section 4.50 (base == 2)
// not a really random base but an interesting (and speedy) one
- BigInteger y = null;
- // FIXME: sadly there a bug that makes this fails for "small" big integers
- if (n.BitCount () > 100)
- y = mr.Pow (2, r);
+ BigInteger y = mr.Pow (2, r);
// still here ? start at round 1 (round 0 was a == 2)
for (int round = 0; round < t; round++) {