示例#1
0
        private void encryptBtn_Click(object sender, EventArgs e)
        {
            var shift = 0;

            if (!string.IsNullOrWhiteSpace(textToEncrypt.Text) && int.TryParse(charShift.Text, out shift))
            {
                if (decryptRB.Checked)
                {
                    shift = shift * -1;
                }

                cipher.Text = CaesarCipher.Encrypt(textToEncrypt.Text, shift);
            }
            else
            {
                textToEncrypt.Text = "INVALID FORM DATA";
            }
        }
示例#2
0
        public override void DisplayMenu()
        {
            int    keyMenu = 0;
            bool   success = false;
            string cipherString;

            Console.WriteLine("Welcome to encryption mode");
            while (String.IsNullOrEmpty(Message))
            {
                Console.WriteLine("Enter message to encrypt:");
                Message = Console.ReadLine();
                if (String.IsNullOrEmpty(Message))
                {
                    ErrorMessage();
                }
            }

            while (!success)
            {
                Console.WriteLine("Enter the key:");
                success = int.TryParse(Console.ReadLine(), out keyMenu);
                if (!success)
                {
                    ErrorMessage();
                }
            }

            Key    = keyMenu;
            Cipher = CaesarCipher.Encrypt(Message, Key);
            Console.WriteLine("The Cipher is: ");
            Console.WriteLine(Cipher);

            cipherString = new String(Cipher);

            WriteToFile(cipherString, Key);

            Console.WriteLine("Press any key to continue");
            Console.ReadLine();
        }