public void RunFindPAndQBBSTest(string TestFile) { List <TestData> TestSets = DataLoader.LoadData(TestFile); foreach (TestData TestSet in TestSets) { string AHexVal = "", ADecVal = "", PHexVal = "", PDecVal = "", QHexVal = "", QDecVal = "", NHexVal = "", NDecVal = ""; TestSet.Parameters.TryGetValue("a", out AHexVal); TestSet.Parameters.TryGetValue("A", out ADecVal); TestSet.Parameters.TryGetValue("p", out PHexVal); TestSet.Parameters.TryGetValue("P", out PDecVal); TestSet.Parameters.TryGetValue("q", out QHexVal); TestSet.Parameters.TryGetValue("Q", out QDecVal); TestSet.Parameters.TryGetValue("n", out NHexVal); TestSet.Parameters.TryGetValue("N", out NDecVal); BigInt A = new BigInt(TestSet.Size, AHexVal); BigInt ADec = new BigInt(TestSet.Size, ADecVal); BigInt P = new BigInt(TestSet.Size, PHexVal); BigInt PDec = new BigInt(TestSet.Size, PDecVal); BigInt Q = new BigInt(TestSet.Size, QHexVal); BigInt QDec = new BigInt(TestSet.Size, QDecVal); BigInt N = new BigInt(TestSet.Size, NHexVal); BigInt NDec = new BigInt(TestSet.Size, NDecVal); BBS Bbs = new BBS(A, (short)A.BitsCount(), true); BBS BbsDec = new BBS(ADec, (short)ADec.BitsCount(), true); BigInt PCal = Bbs.P, PDecCal = BbsDec.P; BigInt QCal = Bbs.Q, QDecCal = BbsDec.Q; BigInt NCal = Bbs.N, NDecCal = BbsDec.N; Assert.True(PCal == P, $"Expected P to be equal to PCal, but got wrong value: {TestSet.Title}."); Assert.True(PDecCal == PDec, $"Expected PDec to be equal to PDecCal, but got wrong value: {TestSet.Title}."); Assert.True(QCal == Q, $"Expected Q to be equal to QCal, but got wrong value: {TestSet.Title}."); Assert.True(QDecCal == QDec, $"Expected QDec to be equal to QDecCal, but got wrong value: {TestSet.Title}."); Assert.True(NCal == N, $"Expected N to be equal to NCal, but got wrong value: {TestSet.Title}."); Assert.True(NDecCal == NDec, $"Expected NDec to be equal to NDecCal, but got wrong value: {TestSet.Title}."); } }
public void RunFindPBBSTest(string TestFile) { List <TestData> TestSets = DataLoader.LoadData(TestFile); foreach (TestData TestSet in TestSets) { string AHexVal = "", ADecVal = "", PHexVal = "", PDecVal = ""; TestSet.Parameters.TryGetValue("a", out AHexVal); TestSet.Parameters.TryGetValue("A", out ADecVal); BigInt A = new BigInt(TestSet.Size, AHexVal); BigInt ADec = new BigInt(TestSet.Size, ADecVal); BBS Bbs = new BBS(A, (short)A.BitsCount(), true); BBS BbsDec = new BBS(ADec, (short)ADec.BitsCount(), true); BigInt P = new BigInt(TestSet.Size, 0), PDec = new BigInt(TestSet.Size, 0), PCal = Bbs.P, PDecCal = BbsDec.P; for (int i = 0; i < 10; i++) { if (i == 0) { TestSet.Parameters.TryGetValue("p", out PHexVal); TestSet.Parameters.TryGetValue("P", out PDecVal); P = new BigInt(TestSet.Size, PHexVal); PDec = new BigInt(TestSet.Size, PDecVal); Assert.True(PCal == P, $"Expected P to be equal to PCal, but got wrong value: {TestSet.Title}."); Assert.True(PDecCal == PDec, $"Expected PDec to be equal to PDecCal, but got wrong value: {TestSet.Title}."); } else { TestSet.Parameters.TryGetValue($"p{i}", out PHexVal); TestSet.Parameters.TryGetValue($"P{i}", out PDecVal); PCal = BBS.GetNextBlumPrime(P); PDecCal = BBS.GetNextBlumPrime(PDec); P = new BigInt(TestSet.Size, PHexVal); PDec = new BigInt(TestSet.Size, PDecVal); Assert.True(PCal == P, $"Expected P to be equal to PCal, but got wrong value: {TestSet.Title}."); Assert.True(PDecCal == PDec, $"Expected PDec to be equal to PDecCal, but got wrong value: {TestSet.Title}."); } } } }
public void RunFermatPseudoPrimeTestsSuccess(string TestFile) { List <TestData> TestSets = DataLoader.LoadData(TestFile); foreach (TestData TestSet in TestSets) { string AHexVal = "", ADecVal = "", PHexVal = "", PDecVal = ""; TestSet.Parameters.TryGetValue("a", out AHexVal); TestSet.Parameters.TryGetValue("A", out ADecVal); TestSet.Parameters.TryGetValue("p", out PHexVal); TestSet.Parameters.TryGetValue("P", out PDecVal); BigInt A = new BigInt(TestSet.Size, AHexVal); BigInt ADec = new BigInt(TestSet.Size, ADecVal); BigInt P = new BigInt(TestSet.Size, PHexVal); BigInt PDec = new BigInt(TestSet.Size, PDecVal); // These instructions always return true (Fermat-Test is unable to detect those numbers), but combined with IsPrimeDiv we got false // Beside Fermat-PseudoPrime-16 (with A = 546 and P = 561, A^(P-1) mod P = 177 and Not 1, which is a correct answer) return false bool isPrimeP = P.IsPrimeFermat(A, true); bool isPrimePDec = PDec.IsPrimeFermat(ADec, true); if (isPrimeP) { Assert.True(isPrimeP == true, $"Expected isPrimeP to be true, but got wrong value: {TestSet.Title}."); Assert.True(isPrimePDec == true, $"Expected isPrimePDec to be true, but got wrong value: {TestSet.Title}."); int PrimeTestListSize = 0; if (P.BitsCount() <= 78) // Number smaller than 3,1*10^23 (78 bit) { PrimeTestListSize = 12; // All prime number less than 41 (It's only necessary to check with primes less or equal to 37) } isPrimeP = isPrimePDec = P.IsPrimeMR(PrimeTestListSize > 0 ? BigIntConfiguration.PRIME_NUMBERS_LIST2000.Take(PrimeTestListSize).ToArray() : BigIntConfiguration.PRIME_NUMBERS_LIST2000); } Assert.True(isPrimeP == false, $"Expected isPrimeP to be false, but got wrong value: {TestSet.Title}."); Assert.True(isPrimePDec == false, $"Expected isPrimePDec to be false, but got wrong value: {TestSet.Title}."); } }