private BigInteger GenerateRandomPrime() { var primeBigInteger = GenerateRandomByLength(keyLength); while (!MillerRabinTest.IsPrime(primeBigInteger, 10)) { primeBigInteger++; } return(primeBigInteger); }
public BigInteger Get(int n) { if (n % 8 != 0) { return(0); } BigInteger res = 0; List <Task> tasks = new List <Task>(); for (int i = 0; i < 20; i++) { tasks.Add(Task.Run(() => { BigInteger number; byte[] bytes = new byte[n / 8]; var rng = new RNGCryptoServiceProvider(); do { lock (locker) { if (!res.IsZero) { return; } } rng.GetBytes(bytes); number = new BigInteger(bytes); if (number < 0) { number *= -1; } }while (!MillerRabinTest.IsPrime(number, 10)); lock (locker) { res = number; } })); } Task.WaitAll(tasks.ToArray()); return(res); }
public void IsProbablyPrimeTest() { var testUnderTest = new MillerRabinTest(10); Assert.IsTrue(testUnderTest.IsPrime(37)); }
public void IsProbablyCompositeTest() { var testUnderTest = new MillerRabinTest(10); Assert.IsFalse(testUnderTest.IsPrime(50)); }
public void BigNotPrime1() { var notPrime1 = new BigInteger(6732366601); // 82051 * 82051 Assert.False(MillerRabinTest.IsPrime(notPrime1, k)); }
public void BigNotPrime2() { var notPrime2 = new BigInteger(4202855089); //58403* 71963 Assert.False(MillerRabinTest.IsPrime(notPrime2, k)); }
public void BigPrime3() { var prime3 = new BigInteger(9418227019); Assert.True(MillerRabinTest.IsPrime(prime3, k)); }
public void BigPrime2() { var prime2 = new BigInteger(2854322099); Assert.True(MillerRabinTest.IsPrime(prime2, k)); }
public void BigPrime1() { var prime1 = new BigInteger(6568056991); Assert.True(MillerRabinTest.IsPrime(prime1, k)); }
public void SimplyTest3() { Assert.False(MillerRabinTest.IsPrime(8, k)); }
public void SimpyTest() { Assert.True(MillerRabinTest.IsPrime(5, k)); }