public bool MillerRabinTest(BigInteger n, int c) { if (n % 2 == 0) { return(false); } BigInteger step = n - 1, s = 0, d; while (step % 2 == 0) { step /= 2; s++; } d = step; // MessageBox.Show(s.ToString()+" "+d.ToString()); BigInteger[] k = new BigInteger[c]; for (int i = 0; i < c; i++) { int x = rand.Next(2, c + 3); while (k.Contains(x)) { x = rand.Next(2, c + 3); } k[i] = x; bool flajok = false; if (BigInteger.ModPow(x, d, n) == 1 || BigInteger.ModPow(x, d, n) % n == n - 1) { return(true); } else { for (int r = 1; r < s; r++) { if (BigInteger.ModPow(x, (int)Math.Pow(2, r) * d, n) % n == n - 1) { flajok = true; break; } } } if (flajok == false) { return(false); } } return(true); }