예제 #1
0
        static void Main(string[] args)
        {
            mpz_t tot = P / 3;

            for (mpz_t roota = 1; roota <= P.Sqrt(); roota++)
            {
                if (roota % 1000 == 0)
                {
                    Console.Write($"\r{roota} : {P.Sqrt()}");
                }
                for (mpz_t rootc = roota + 1; ; rootc++)
                {
                    mpz_t a = roota.Power(2);
                    mpz_t c = rootc.Power(2);
                    mpz_t b = roota.Multiply(rootc);
                    if (a + b + c > P || c > a + b)
                    {
                        break;
                    }
                    //if (mpz_t.Gcd(a, c) == 1)
                    {
                        Console.WriteLine($"{a},{b},{c}  {roota} / {rootc}{(mpz_t.Gcd(a,c) > 1 ? " M" : "")}");
                        tot += P.Divide(a + b + c);
                    }
                }
                Console.WriteLine();
            }
            Console.WriteLine(tot);
        }
예제 #2
0
        /// <summary>
        /// Generate a response packet.
        /// </summary>
        /// <param name="request">The string representation of the request.</param>
        /// <returns></returns>
        public byte[] GenerateResponse(byte[] request)
        {
            var currentPlatform = OSCheck.RunningPlatform();

            if (currentPlatform == OSCheck.Platform.Mac)
            {
                throw new PlatformNotSupportedException("Mac OSX is not a supported operating system for this.");
            }

            var instream = new MemoryStream(request);
            var gData    = DataUtility.ReadBytesFromStream(instream);
            var pData    = DataUtility.ReadBytesFromStream(instream);
            var AData    = DataUtility.ReadBytesFromStream(instream);

            byte[] BData = null;

            if (currentPlatform == OSCheck.Platform.Windows)
            {
                g = new mpz_t(gData, 1);
                p = new mpz_t(pData, 1);
                var A = new mpz_t(AData, 1);

                // Generate the parameters.
                a = RandomGenerator.Next(bytes);
                var B = g.Power(a);
                B = B.Mod(p);

                // Get Raw IntX Data
                BData = B.ToByteArray(1);

                // Got the key!!! HOORAY!
                S = A.Power(a);
                S = S.Mod(p);
                W_GetKeyData();
            }
            else if (currentPlatform == OSCheck.Platform.Linux)
            {
                g = new Integer();
                g.FromBytes(gData);
                p = new Integer();
                p.FromBytes(pData);
                var A = new Integer(AData);

                // Generate the parameters.
                a = RandomGenerator.Next(bytes);
                var B = g.Pow(a);
                B %= p;

                // Get Raw IntX Data
                BData = B.ToBytes();

                // Got the key!!! HOORAY!
                S  = A.Pow(a);
                S %= p;
                L_GetKeyData();
            }
            return(BData);
        }
예제 #3
0
 static int NumPrimes(int a, int b)
 {
     for (int n = 0; ; n++)
     {
         mpz_t bign = new mpz_t(n);
         mpz_t p    = bign.Power(2) + bign.Multiply(a) + b;
         if (!p.IsProbablyPrimeRabinMiller(10))
         {
             return(n);
         }
     }
 }
예제 #4
0
        static void Main(string[] args)
        {
            int tot = 0;

            for (mpz_t i = 0; i <= 50000000; i++)
            {
                if (i.Mod(10000) == 0)
                {
                    Console.Write($"{(int)i:#,##0}   \r");
                }
                var tn = 2 * i.Power(2) - 1;
                if (tn.IsProbablyPrimeRabinMiller(10))
                {
                    tot++;
                }
            }
            Console.WriteLine();
            Console.WriteLine(tot);
        }
예제 #5
0
        /// <summary>
        /// Generates the key after a response is received.
        /// </summary>
        /// <param name="response">The string representation of the response.</param>
        public void HandleResponse(byte[] response)
        {
            var currentPlatform = OSCheck.RunningPlatform();

            if (currentPlatform == OSCheck.Platform.Mac)
            {
                throw new PlatformNotSupportedException("Mac OSX is not a supported operating system for this.");
            }
            if (currentPlatform == OSCheck.Platform.Windows)
            {
                var B = new mpz_t(response, 1);

                S = B.Power(a);
                S = (S as mpz_t).Mod((p as mpz_t));
                W_GetKeyData();
            }
            else if (currentPlatform == OSCheck.Platform.Linux)
            {
                var B = new Integer(response);
                S  = B.Pow(a);
                S %= p;
                L_GetKeyData();
            }
        }