TLSharp.Core.MTProto.Crypto.Factorizator.findSmallMultiplierLopatin C# (CSharp) Method

findSmallMultiplierLopatin() public static method

public static findSmallMultiplierLopatin ( long what ) : long
what long
return long
        public static long findSmallMultiplierLopatin(long what)
        {
            long g = 0;
            for (int i = 0; i < 3; i++)
            {
                int q = (random.Next(128) & 15) + 17;
                long x = random.Next(1000000000) + 1, y = x;
                int lim = 1 << (i + 18);
                for (int j = 1; j < lim; j++)
                {
                    long a = x, b = x, c = q;
                    while (b != 0)
                    {
                        if ((b & 1) != 0)
                        {
                            c += a;
                            if (c >= what)
                            {
                                c -= what;
                            }
                        }
                        a += a;
                        if (a >= what)
                        {
                            a -= what;
                        }
                        b >>= 1;
                    }
                    x = c;
                    long z = x < y ? y - x : x - y;
                    g = GCD(z, what);
                    if (g != 1)
                    {
                        break;
                    }
                    if ((j & (j - 1)) == 0)
                    {
                        y = x;
                    }
                }
                if (g > 1)
                {
                    break;
                }
            }

            long p = what / g;
            return Math.Min(p, g);
        }