Esempio n. 1
0
        public static BigInteger2 getProbablePrime(int n)
        {
            BigInteger2 num     = new BigInteger2(n);
            BigInteger2 zero    = BigInteger2.Zero();
            BigInteger2 temp    = new BigInteger2(1, 0);
            BigInteger2 nem     = ((BigInteger2)num.Clone()) + BigInteger2.T50();
            bool        success = true;
            int         ni      = 0;

            while (true)
            {
                ni++;
                Console.Out.WriteLine(ni);
                if (num < nem || num == nem)
                {
                    foreach (int i in mySet)
                    {
                        bool[] val = BigInteger2.ConvertToBinary(i, 11);
                        bool[] t   = new bool[val.Length];
                        for (int x = 0; x < val.Length; x++)
                        {
                            t[x] = (val[x] ? true : false);
                        }
                        temp.bitlength = t;
                        if (BigIntegerExtensions.DivideBy(num, temp)[1] == zero)
                        {
                            success = false;
                            break;
                        }
                    }
                }
                if (success && BigIntegerExtensions.MillerRabinIsPrime(num))
                {
                    break;
                }
                if (num == nem)
                {
                    success = true;
                    var skip = DateTime.Now.Millisecond % 5;
                    switch (skip)
                    {
                    case 0:

                        num = num + BigInteger2.TWO();
                        nem = nem + BigInteger2.T50();
                        break;

                    case 1:
                        num = num + BigInteger2.FOUR();
                        nem = nem + BigInteger2.T100();
                        break;

                    case 2:
                        num = num + BigInteger2.T16();
                        nem = nem + BigInteger2.T100();
                        break;

                    case 3:
                        num = num + BigInteger2.T32();
                        nem = nem + BigInteger2.T100();
                        break;

                    case 4:
                        num = num + BigInteger2.T50();
                        nem = nem + BigInteger2.T100();
                        break;
                    }
                }
                else
                {
                    success = true;
                    num     = num + BigInteger2.TWO();
                }
            }
            return(num);
        }