예제 #1
0
        static void Main(string[] args)
        {
            RSAEncryption encryptionObj = GeneratePublicPrivateKeys();

            do
            {
                //Console.WriteLine("Hello World! \nWelcome to RSA algorithm of generating Public-Private Keys. \nPress 'q' to Quit..");
                Console.WriteLine("Welcome to RSA Encryption algorithm of generating Public-Private Keys.\nPress 'q' to Quit from the program..");

                encryptionObj.Display();

                int ToSend = 0;

                Console.WriteLine("Hey Bob, Enter the number to send to Alice: ");

                try
                {
                    ToSend = int.Parse(Console.ReadLine());
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: {0}", e.Message);
                }

                Console.WriteLine("Now Let's say Bob wants to send Alice : {0}", ToSend);

                Console.WriteLine("Alice asks Bob to send m ^ {e} mod (n) instead of sending m directly");

                Console.WriteLine("Alice confidently shares e = {0} and n = {1} knowing well that the message could be intruded by Eve", encryptionObj.e, encryptionObj.n);

                BigInteger msgSent = ((BigInteger.Pow(ToSend, encryptionObj.e)) % encryptionObj.n);

                Console.WriteLine("So now Bob tries to send m ^ e mod (n) = {0} ^ {1} mod ({2}) = {3} (Let's call that msgSent)", ToSend, encryptionObj.e, encryptionObj.n, msgSent);

                Console.WriteLine("So now Alice tries to decrypt the message using msgSent ^ d mod (n) = {0} ^ {1} mod ({2}) = {3}", msgSent, encryptionObj.d, encryptionObj.n, ((BigInteger.Pow(msgSent, encryptionObj.d)) % encryptionObj.n));
            } while (!Console.ReadKey().Equals("q"));
        }