Пример #1
0
        private static void ShowCaesarEncryption()
        {
            Console.WriteLine("--*-- Caesar Cipher example --*--");
            Console.WriteLine("Type a string to encrypt (or hit Enter to continue with default): ");
            string inputText = Console.ReadLine();

            if (inputText == "")
            {
                inputText = plainText;
            }

            Console.WriteLine("Enter the key value (numberic)");
            string key    = Console.ReadLine();
            int    intKey = 0;

            if (!Int32.TryParse(key, out intKey))
            {
                intKey = -1;
            }

            Console.WriteLine("Encrypted text input with Caesar Cipher by {0} spaces:", intKey);

            string cipherText = CaesarCipher.Encipher(inputText, intKey);

            Console.WriteLine(cipherText);
            Console.Write("\n");

            Console.WriteLine("Decrypted Data:");

            string t = CaesarCipher.Decipher(cipherText, intKey);

            Console.WriteLine(t);
        }
Пример #2
0
        public ActionResult Index()
        {
            string password = "******";



            int key = Convert.ToInt32(-2);


            string cipherText = CaesarCipher.Encipher(password, key);

            string t = CaesarCipher.Decipher(cipherText, key);


            string burak = "";

            return(View());
        }
Пример #3
0
        private void cipherButton_Click(object sender, EventArgs e)
        {
            // This text is added only once to the file.
            if (!File.Exists(plainTextPath))
            {
                return;
            }

            string plainText = File.ReadAllText(plainTextPath);

            if (!plainText.All(c => Char.IsLetterOrDigit(c) || c == ' '))
            {
                MessageBox.Show("The text must contains only alphanumeric characters in order to be encrypted!",
                                "Invalid input!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string vigenereKey = vigenereKeyTextBox.Text;

            if (!vigenereKey.All(c => Char.IsLetterOrDigit(c) || c == ' '))
            {
                MessageBox.Show("The key must contains only alphanumeric characters in order to be encrypted!",
                                "Invalid key!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var vigenereEncryptionText = VigenereCipher.Encipher(plainText, vigenereKey);

            vigenereCipherRichTextBox.Text = vigenereEncryptionText;


            int caesarKey  = Convert.ToInt32(caesarKeyNumericUpDown.Value);
            var cipherText = CaesarCipher.Encipher(vigenereEncryptionText, caesarKey);

            cipherTextRichTextBox.Text = cipherText;

            File.WriteAllText(cipherTextPath, cipherText);
        }
Пример #4
0
 public void CaesarCipherTest(string expected, string plaintext, int rot, bool squash = false)
 {
     Assert.AreEqual(expected, CaesarCipher.Encipher(plaintext, rot, squash));
 }