Пример #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 decipherButton_Click(object sender, EventArgs e)
        {
            // This text is added only once to the file.
            if (!File.Exists(cipherTextPath))
            {
                return;
            }

            string cipherText  = File.ReadAllText(cipherTextPath);
            string vigenereKey = vigenereKeyTextBox.Text;

            if (!cipherText.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;
            }

            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 vigenereDecryptionText = VigenereCipher.Decipher(cipherText, vigenereKey);

            vigenereCipherRichTextBox.Text = vigenereDecryptionText;

            int caesarKey = Convert.ToInt32(caesarKeyNumericUpDown.Value);
            var plainText = CaesarCipher.Decipher(vigenereDecryptionText, caesarKey);

            plainTextRichTextBox.Text = plainText;

            File.WriteAllText(plainTextPath, plainText);
        }
Пример #4
0
 public void CaesarDecipherTest(string expected, string ciphered, int rot, bool squash = false)
 {
     Assert.AreEqual(expected, CaesarCipher.Decipher(ciphered, rot, squash));
 }