Esempio n. 1
0
        private static void LogPrime(BigInteger prime, TimeSpan timeElapsed, int cursorTopPosition, int count)
        {
            string primeText = prime.ToString();

            if (Settings.Verbose_Mode)
            {
                string log10prime = (Math.Round(BigInteger.Log10(prime))).ToString("F0");
                string log2prime  = (Math.Round(CryptographicPrimeGenerator.Log2(prime))).ToString("F0");

                Console.WriteLine("] {0} (time elapsed)", AggregateTimer.FormatTimeSpan(timeElapsed));
                Console.WriteLine();
                Console.WriteLine(" OUTPUT:  ..\\{0}", Settings.LogFile_Primes.ToUpperInvariant());

                int saveCursorTop = Console.CursorTop;
                Console.SetCursorPosition(0, cursorTopPosition);
                Console.WriteLine(" ACTUAL SIZE: {0} bits ({1} decimal digits)", log2prime, log10prime);
                Console.SetCursorPosition(0, saveCursorTop);
                Console.WriteLine();

                string fileOutput = string.Format("{1} bit prime ({2} digits):{0}{3}{0}", Environment.NewLine, log2prime, log10prime, primeText);
                WriteLogFile(Settings.LogFile_Primes, fileOutput);
            }
            else
            {
                WriteLogFile(Settings.LogFile_Primes, primeText);
            }
            Console.Write(string.Format("({0})", count.ToString()));
        }
Esempio n. 2
0
        private void FindPrimes_WorkerComplete(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                WriteMessageBox(e.Error.ToString(), "Exception Message");
            }
            else if (e.Cancelled)
            {
                WriteOutputTextboxLine("Task was canceled.", true);
            }
            else
            {
                BigInteger prime1 = (BigInteger)e.Result;

                string primeNumber = prime1.ToString();
                string base10size  = (Math.Round(BigInteger.Log10(prime1))).ToString("F0");
                string base2size   = (Math.Round(CryptographicPrimeGenerator.Log2(prime1))).ToString("F0");

                //.... Print bit array
                DateTime bitStringStart1 = DateTime.Now;
                byte[]   byteArray1      = prime1.ToByteArray();
                BitArray bitArray1       = new BitArray(byteArray1);
                string   bitString1      =
                    new string(
                        bitArray1.Cast <bool>()
                        .Reverse()
                        .SkipWhile(b => !b)
                        .Select(b => b ? '1' : '0')
                        .ToArray()
                        );
                //string bitCountString1 = bitString1.Length.ToString();
                TimeSpan bitStringTime1 = DateTime.Now.Subtract(bitStringStart1);
                WriteOutputTextboxLine("");

                //.... PRINT
                WriteOutputTextboxLine(string.Format("{0} bit prime ({1} digits):", base2size, base10size));
                WriteOutputTextboxLine(primeNumber);
                //WriteOutputLine(string.Format("Bits ({0}):", log2prime));
                //WriteOutputLine(bitString1+Environment.NewLine);

                //... Print run/processing time
                if (algorithmWorker.RuntimeTimer != null && algorithmWorker.RuntimeTimer != TimeSpan.Zero)
                {
                    WriteOutputTextboxLine(string.Format("Run time: {0}", AggregateTimer.FormatTimeSpan(algorithmWorker.RuntimeTimer)));
                    WriteOutputTextboxLine(string.Format("Time to render: {0}", AggregateTimer.FormatTimeSpan(bitStringTime1)));
                }
            }

            DisposeThreadedAlgorithmWorker();

            IsBusy = false;
            SetButtonText(true, "Search for primes...");
        }