Exemple #1
0
        static void Main(string[] args)
        {
            System.Diagnostics.Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
            RSA rsa = new RSA();

            //rsa = new RSA(128);
            //rsa.GenerateNumber_TEST();
            //rsa.isPrime_TEST();
            //rsa.isPrimeExtended_TEST();
            //rsa.GeneratePrimeNumber_TEST();
            //rsa.PowerRaise_TEST();
            //rsa.RSA_NG_TEST();

            //rsa.RSA_NG_RunTest4();
            //rsa.RSA_NG_RunTest5();
            //rsa.crypt(cryptFile: true, file: "./abc.txt");
            //rsa.crypt(cryptFile: false, file: "./abc_^.txt");
            //rsa.crypt(cryptFile: true, file: "./test_text.txt");
            //rsa.crypt(cryptFile: false, file: "./test_text_^.txt");
            //rsa.runDemo(BigInteger.Parse("3436456456307890879068577654435634564578684769241111753453453400000234235235"));

            if (args.Length > 0)
            {
                switch (args[0])
                {
                    case "-g": if (args.Length > 1) rsa = new RSA(Convert.ToInt32(args[1])); break;
                    case "-a": if (args.Length > 1) rsa.runDemo(BigInteger.Parse(args[1])); break;
                    case "-c": if (args.Length > 1) rsa.crypt(cryptFile: true, file: args[1]); else rsa.crypt(cryptFile: true); break;
                    case "-d": if (args.Length > 1) rsa.crypt(cryptFile: false, file: args[1]); else rsa.crypt(cryptFile: false); break;
                    case "-4": rsa.RSA_NG_RunTest4(); break;
                    case "-5": if (args.Length > 1) rsa.RSA_NG_RunTest5(Convert.ToInt32(args[1])); break;
                    case "-n": if (args.Length > 1) Console.WriteLine(rsa.RSA_NG(BigInteger.Parse(args[1]))); break;
                }
            }
        }
Exemple #2
0
 public void RSA_NG_RunTest5(int length = 70)
 {
     RSA rsa = new RSA();
     Stopwatch stopwatch = new Stopwatch();
     StreamWriter sww = new StreamWriter("./test5.txt");
     sww.Close();
     BigInteger cracked = 0;
     for (double i = 0.25; i <= 0.5; i+=0.05)
     {
         // Start measurement
         rsa = new RSA(length, i);
         stopwatch.Reset();
         stopwatch.Start();
         cracked = rsa.RSA_NG(rsa.nModule);
         // Stop measurement
         stopwatch.Stop();
         TimeSpan timespan = stopwatch.Elapsed;
         string elapsedTime = String.Format("{0:0.00}. {1:00}:{2:00}:{3:00}.{4:00} ## {5:000000000000} ## {6} {7} {8}",
         i, timespan.Hours, timespan.Minutes, timespan.Seconds,
         timespan.Milliseconds / 10, timespan.TotalMilliseconds, rsa.nModule, cracked, rsa.nModule / cracked);
         Console.WriteLine(elapsedTime);
         // Write file
         try
         {
             using (StreamWriter sw = new StreamWriter("./test5.txt", append: true))
             {
                 sw.WriteLine(elapsedTime);
             }
             Console.WriteLine("-- Key cracked successfully!\n\n");
         }
         catch (Exception a)
         {
             Console.WriteLine(a);
         }
     }
 }