示例#1
0
 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();
 }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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;
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
 public void TestSum()
 {
     Assert.AreEqual(NumbersOperations.GetSum(5, 7), 12);
 }
示例#8
0
 public void FindNthRootTests_WithWrongAccuracyLess0_ThrowArgumentOutOfRangeException()
 => Assert.Throws <ArgumentOutOfRangeException>(() => NumbersOperations.FindNthRoot(1, 10, -10));
示例#9
0
 public void FindNthRootTests_WithWrongPower_ThrowArgumentOutOfRangeException()
 => Assert.Throws <ArgumentOutOfRangeException>(() => NumbersOperations.FindNthRoot(1, -10, 0.001));
示例#10
0
 public double FindNthRootTests(double number, int power, double accuracy)
 => NumbersOperations.FindNthRoot(number, power, accuracy);
示例#11
0
 public void FilterDigitTests_WithWrongDigitLess1_ThrowArgumentOutOfRangeException()
 => Assert.Throws <ArgumentOutOfRangeException>(() => NumbersOperations.FilterDigit(new List <int> {
     1, 3, 4
 }, -10));
示例#12
0
 public void FilterDigitTests_WithNullList_ThrowArgumentNullException()
 => Assert.Throws <ArgumentNullException>(() => NumbersOperations.FilterDigit(null, 3));
示例#13
0
 public void NextBiggerThanTests_WithIncorrentI_ThrowArgumentException()
 => Assert.Throws <ArgumentException>(() => NumbersOperations.NextBiggerThan(-1));
示例#14
0
 public int?NextBiggerThanTests(int number) => NumbersOperations.NextBiggerThan(number);
示例#15
0
 public void FindNthRootTests_WithNumberLess0AndSquareRoot_ThrowArgumentException()
 => Assert.Throws <ArgumentException>(() => NumbersOperations.FindNthRoot(-10, 2, 0.001));
示例#16
0
 public void TestDivision()
 {
     Assert.AreNotEqual(NumbersOperations.GetDivision(15, 3), 0);
 }
示例#17
0
 public void TestEven()
 {
     Assert.IsTrue(NumbersOperations.IsEven(2), "„исло 2 четное");
 }
示例#18
0
 public void FilterDigitTests_WithEmptyList_ThrowArgumentException()
 => Assert.Throws <ArgumentException>(() => NumbersOperations.FilterDigit(new List <int>(), 3));