Esempio n. 1
0
        static void Main(string[] args)
        {
            var    cipher = new VigenereCipher();
            string language;

            while (true)
            {
                Console.Write("Enter the required language (\"RU\" or \"EN\"): ");
                var answer = Console.ReadLine();
                if (answer == "RU")
                {
                    language = "RU";
                    break;
                }
                else if (answer == "EN")
                {
                    language = "EN";
                    break;
                }
            }
            Console.Write("Enter text: ");
            var message = Console.ReadLine().ToUpper();

            Console.Write("Enter key: ");
            var key           = Console.ReadLine().ToUpper();
            var encryptedText = cipher.Encrypt(language, message, key);

            Console.WriteLine("Encrypted message: {0}", encryptedText);
            Console.WriteLine("Decrypted message: {0}", cipher.Decrypt(language, encryptedText, key));
            Console.ReadLine();
        }
        public static void ShowAnswers()
        {
            Console.WriteLine("Showing Vigenere decryption:");

            var currentKey     = FileHelper.GetKey("VigenereFirstTask.txt");
            var currentMessage = FileHelper.GetMessage("VigenereFirstTask.txt");

            Console.WriteLine($"Vigenere first decryption. Key = {currentKey}:");
            foreach (var decryption in VigenereCipher.Decrypt(currentMessage, currentKey))
            {
                Console.Write(decryption);
            }

            currentMessage = FileHelper.GetMessage("VigenereSecondTask.txt");
            Console.WriteLine($"{Environment.NewLine}Vigenere second decryption.");
            foreach (var decryption in VigenereCipher.DecryptFromFrequencies(currentMessage, 7))
            {
                Console.WriteLine(decryption);
            }

            currentMessage = FileHelper.GetMessage("VigenereThirdTask.txt");
            Console.WriteLine($"Vigenere third decryption.");
            foreach (var decryption in VigenereCipher.DecryptFromFrequencies(currentMessage, 6))
            {
                Console.WriteLine(decryption);
            }

            currentKey     = FileHelper.GetKey("VigenereFouthTask.txt");
            currentMessage = FileHelper.GetMessage("VigenereFouthTask.txt");
            Console.WriteLine($"Vigenere fourth decryption. Key = {currentKey}:");
            foreach (var decryption in VigenereAutoKeyCipher.Decrypt(currentMessage, currentKey))
            {
                Console.WriteLine(decryption);
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            string         alphabet = "abcdefghijklmnopqrstuvwxyz";
            VigenereCipher cipher   = new VigenereCipher(alphabet);

            string key            = "battista";
            string plainText      = "this is a test message.";
            string cipherText     = cipher.Encrypt(plainText, key);
            string decipheredText = cipher.Decrypt(cipherText, key);

            Console.WriteLine($"Plaintext: {plainText}");
            Console.WriteLine($"Key: {key}");
            Console.WriteLine($"Lengthen Key: {cipher.LengthenKey(key, plainText)}");
            Console.WriteLine($"Ciphertext: {cipherText}");
            Console.WriteLine($"Deciphered: {decipheredText}");
        }
Esempio n. 4
0
        //User gives message and key and the message will be decrypted
        public static void Decrypt()
        {
            Console.WriteLine("Your Message: ");
            string message = Console.ReadLine();

            Console.WriteLine("Your Key: ");
            string key = Console.ReadLine();

            string decryption = VigenereCipher.Decrypt(message, key);

            for (int i = 0; i <= 100; i++)
            {
                Console.Write($"\rDecrypting: {i}%   ");
                Thread.Sleep(25);
            }
            Thread.Sleep(1000);
            Console.WriteLine("\rDecrypted message: " + decryption);
        }