Beispiel #1
0
    public void decrypt()
    {
        var polybius = new PolybiusSquare();
        var message  = System.IO.File.ReadAllText(input2);

        Console.WriteLine("Зашифрованный текст: " + message);
        Console.Write("Введите ключ: ");
        var pass       = Console.ReadLine().ToUpper();
        var cipherText = polybius.PolybiusDecrypt(message, pass);

        Console.WriteLine("Расшифрованный текст: {0}", cipherText);
        System.IO.File.WriteAllText(output1, cipherText);
    }
Beispiel #2
0
        static void Main(string[] args)
        {
            PolybiusSquare polybiusSquare = new PolybiusSquare();

            do
            {
                Console.Clear();
                int modeCode = Parser.ParseInt("Chose mode.\n" +
                                               "1. Read encrypted message from file.\n" +
                                               "2. Write encrypted message to file.\n" +
                                               "3. Set message.\n" +
                                               "4. Encrypt message.\n" +
                                               "5. Decrypt message.\n" +
                                               "6. Print message.\n" +
                                               "7. Print encrypted messgae.\n" +
                                               "8. Exit.\n\n" +
                                               "Enter: ");
                try
                {
                    Console.Clear();
                    switch (modeCode)
                    {
                    case 1: polybiusSquare.ReadEncryptedMessage(); Console.WriteLine("File path: " + polybiusSquare.Path); break;

                    case 2: polybiusSquare.WriteEncryptedMessage(); Console.WriteLine("File path: " + polybiusSquare.Path); break;

                    case 3: Console.Write("Enter message: "); polybiusSquare.Message = Console.ReadLine(); break;

                    case 4: polybiusSquare.TryEncryptMessage(); Console.WriteLine("The message was successfully encrypted."); break;

                    case 5: polybiusSquare.TryDecryptMessage(); Console.WriteLine("The message was successfully decrypted."); break;

                    case 6: Console.WriteLine("The message: " + polybiusSquare.Message); break;

                    case 7: Console.WriteLine("The encrypted message: " + polybiusSquare.EncryptedMessage); break;

                    case 8: return;

                    default: Console.WriteLine("Incorrect value."); break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            } while (true);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            StreamReader sr      = new StreamReader("message.txt");
            var          message = sr.ReadToEnd();

            sr.Close();
            string encrypted = PolybiusSquare.Encrypt(message);
            string decrypted = PolybiusSquare.Decrypt(encrypted);

            StreamWriter sw = new StreamWriter("output.txt");

            sw.WriteLine(decrypted);
            sw.Close();
            System.Console.WriteLine((int)Math.Sqrt(120) + 1);
            // Console.WriteLine(encrypted);
        }
Beispiel #4
0
    static void Main(string[] args)
    {
        var polybius = new PolybiusSquare();

        Console.Write("Введите текст: ");
        var message = Console.ReadLine().ToUpper();

        Console.Write("Введите пароль(без повторов букв): ");
        var pass       = Console.ReadLine().ToUpper();
        var cipherText = polybius.PolibiusEncrypt(message, pass);

        Console.WriteLine("Зашифрованный текст: {0}", cipherText);
        Console.WriteLine("Расшифрованный текст: {0}",
                          polybius.PolybiusDecrypt(cipherText, pass));
        Console.ReadLine();
    }
        public void FourSquare()
        {
            FourSquareCipher cipher = new FourSquareCipher();

            char[, ][,] key =
            {
                { PolybiusSquare.CreateFromString(Charsets.EnglishWithoutQ), PolybiusSquare.CreateFromKeyword("KEYWORD", Charsets.EnglishWithoutQ)                                 },
                { PolybiusSquare.CreateFromKeyword("EXAMPLE",                Charsets.EnglishWithoutQ),                  PolybiusSquare.CreateFromString(Charsets.EnglishWithoutQ) }
            };

            const string plaintext  = "Help me Obiwan Kenobi";
            const string ciphertext = "Fygm ky Hobxmf Kkkimd";

            Assert.AreEqual(ciphertext, cipher.Encrypt(plaintext, key));
            Assert.AreEqual(plaintext, cipher.Decrypt(ciphertext, key));
        }
        public void TwoSquare()
        {
            TwoSquareCipher cipher = new TwoSquareCipher();

            char[][,] key =
            {
                PolybiusSquare.CreateFromKeyword("EXAMPLE", Charsets.EnglishWithoutQ),
                PolybiusSquare.CreateFromKeyword("KEYWORD", Charsets.EnglishWithoutQ)
            };

            const string plaintext  = "Help me Obiwan Kenobi";
            const string ciphertext = "Hedl xw Sdjyan Hotkdg";

            Assert.AreEqual(ciphertext, cipher.Encrypt(plaintext, key));
            Assert.AreEqual(plaintext, cipher.Decrypt(ciphertext, key));
        }