Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            var info = new string[2];
            Console.WriteLine("Welcome in Prime Numbers Generator!");

            A1:
            Console.WriteLine("Plase enter how many numbers u want to generate");
            info[0] = Console.ReadLine();

            Console.WriteLine("Please enter how many bits should this numbers contain");
            info[1] = Console.ReadLine();
            var results = InputChecker.CheckInput(info); //info[0]- k  info[1]-d
            if (results == null)
            {
                Console.WriteLine("Incorrect numbers. Please try again! ");
                goto A1;
            }

            /***************************************Input_Loaded*********************************************/

            Console.WriteLine("Random Prime Numbers creation started!");
            var gen = new Generator();
            gen.PrepeareThreads(results[1], Tests, results[0]);
            gen.StartThreads();
            Console.ReadKey();
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            Console.WriteLine("RSA Keys Generator");
            Console.WriteLine("Author: Szymon Sutek");

            A1:
            Console.WriteLine("Please enter bits number for keys size!");
            var buffer = InputChecker.CheckInput(Console.ReadLine());
            if (buffer == -1)
            {
                Console.WriteLine("Incorrect numbers. Please try again! ");
                goto A1;
            }

            //************************EXECUTING_RSA_ALGORITHM****************************//

            var gen = new Generator();
            KeyGenerator.SetPath(@"C: \Users\Simon\Desktop\Kryptografia\");
            KeyGenerator.Rsa(gen, buffer);

            //************************KEY_PAIRS_CREATED**********************************//
            var list1 = KeyGenerator.GetEncryptionKeys();
            var list2 = KeyGenerator.GetDecryptionKeys();

            Console.WriteLine("\nPrinting keys: ");
            Console.WriteLine("E is equalto: " + list1[0]);
            Console.WriteLine("D is equalto: " + list2[0]);
            Console.WriteLine("N is equalto: " + list1[1]);
            Console.ReadKey();
        }
        //*******************RSA_ALGORITHM*********************//
        public static void Rsa(Generator gen, int bufferSize)
        {
            GenerateN(gen, bufferSize);
            GENERATE:
            GenerateE(gen, bufferSize);
            try
            {
                GenerateD(gen, bufferSize);
            }
            catch (Exception)
            {
                goto GENERATE;
            }

            WriteToFile();
        }
        private static void GenerateN(Generator gen, int bufferSize)
        {
            AGAIN:
            var p = gen.ReturnPrime(bufferSize, TestPrecision);
            var q = gen.ReturnPrime(bufferSize, TestPrecision);

            if (BigInteger.Compare(p, q) == BigInteger.Zero)
                goto AGAIN;

            _n = BigInteger.Multiply(p, q);
            Fi(p, q);
        }
 private static void GenerateE(Generator gen, int bufferSize)
 {
     while (true)
     {
         var e = gen.ReturnPrime(bufferSize, TestPrecision);
         if (BigInteger.Compare(e, _eulerFunction) < 0)
         {
             _e = e;
             return;
         }
     }
 }
 private static void GenerateD(Generator gen, int bufferSize)
 {
     _d = EuclidianAlgorithm(_e, _eulerFunction);
 }
Exemplo n.º 7
0
 private static void GenerateD(Generator gen, int bufferSize)
 {
     _d = BigInteger.Divide(BigInteger.One, _e);
     _dP = BigInteger.ModPow(_d, BigInteger.One, BigInteger.Subtract(_p, BigInteger.One));
     _dQ = BigInteger.ModPow(_d, BigInteger.One, BigInteger.Subtract(_q, BigInteger.One));
     _qInv = BigInteger.ModPow( (1/_q),BigInteger.One,  _p);
 }