public Form1() { InitializeComponent(); textBoxP.Text = "2147483647"; textBoxG.Text = NumbersOperations.Random(2, BigInteger.Parse(textBoxP.Text) - 1).ToString(); textBoxK_B.Text = NumbersOperations.Random(2, BigInteger.Parse(textBoxP.Text) - 1).ToString(); }
public void FilterDigitTests_WithNormalList_2() { var resultList = new List <int> { 30, 3, 33, 3333, 3 }; var resultMethod = NumbersOperations.FilterDigit(new List <int> { 30, 10, 3, 33, 3333, 1, 3 }, 3); Assert.AreEqual(resultList, resultMethod); }
public void FilterDigitTests_WithNormalList() { var resultList = new List <int> { 7, 70, 17 }; var resultMethod = NumbersOperations.FilterDigit(new List <int> { 7, 1, 2, 3, 4, 5, 6, 68, 69, 70, 15, 17 }, 7); Assert.AreEqual(resultList, resultMethod); }
public static void Encode(BigInteger p, BigInteger g, BigInteger k_B, BigInteger m_A, out BigInteger r, out BigInteger e) { var d_B = BigInteger.ModPow(g, k_B, p); BigInteger k_A; do { k_A = NumbersOperations.Random(2, p - 1); }while (BigInteger.GreatestCommonDivisor(k_A, p - 1) != 1); r = BigInteger.ModPow(g, k_A, p); e = (BigInteger.ModPow(d_B, k_A, p) * (m_A % p)) % p; }
public static bool IsPrime(int n, int error) { int a; var random = new Random(); for (int i = 0; i < error; i++) { a = random.Next(2, n); if (NumbersOperations.NSD(a, n) > 1) { return(false); } if (NumbersOperations.ModPow(a, (n - 1) / 2, n) != (n + Jacobi(a, n)) % n) { return(false); } } return(true); }
private static int Jacobi(int x, int n) { if (NumbersOperations.NSD(x, n) != 1) { return(0); } int result = 1; do { int y = 0; while (x % 2 == 0) { y += 1; x /= 2; } if ((y % 2 == 1 && (n % 8 == 3 || n % 8 == 5)) || (x % 4 == 3 && n % 4 == 3)) { result = -result; } //if (x % 4 == 3 && n % 4 == 3) //{ // result = -result; //} int temp = x; x = n % temp; n = temp; } while (x != 0); return(result); }
public void TestSum() { Assert.AreEqual(NumbersOperations.GetSum(5, 7), 12); }
public void FindNthRootTests_WithWrongAccuracyLess0_ThrowArgumentOutOfRangeException() => Assert.Throws <ArgumentOutOfRangeException>(() => NumbersOperations.FindNthRoot(1, 10, -10));
public void FindNthRootTests_WithWrongPower_ThrowArgumentOutOfRangeException() => Assert.Throws <ArgumentOutOfRangeException>(() => NumbersOperations.FindNthRoot(1, -10, 0.001));
public double FindNthRootTests(double number, int power, double accuracy) => NumbersOperations.FindNthRoot(number, power, accuracy);
public void FilterDigitTests_WithWrongDigitLess1_ThrowArgumentOutOfRangeException() => Assert.Throws <ArgumentOutOfRangeException>(() => NumbersOperations.FilterDigit(new List <int> { 1, 3, 4 }, -10));
public void FilterDigitTests_WithNullList_ThrowArgumentNullException() => Assert.Throws <ArgumentNullException>(() => NumbersOperations.FilterDigit(null, 3));
public void NextBiggerThanTests_WithIncorrentI_ThrowArgumentException() => Assert.Throws <ArgumentException>(() => NumbersOperations.NextBiggerThan(-1));
public int?NextBiggerThanTests(int number) => NumbersOperations.NextBiggerThan(number);
public void FindNthRootTests_WithNumberLess0AndSquareRoot_ThrowArgumentException() => Assert.Throws <ArgumentException>(() => NumbersOperations.FindNthRoot(-10, 2, 0.001));
public void TestDivision() { Assert.AreNotEqual(NumbersOperations.GetDivision(15, 3), 0); }
public void TestEven() { Assert.IsTrue(NumbersOperations.IsEven(2), "„исло 2 четное"); }
public void FilterDigitTests_WithEmptyList_ThrowArgumentException() => Assert.Throws <ArgumentException>(() => NumbersOperations.FilterDigit(new List <int>(), 3));