Пример #1
0
        static void Vigenere(bool isEncrypt = true)
        {
            Console.WriteLine("Vigenere");


            var userInput = "";
            var key       = "";


            do
            {
                Console.Write("Enter the Key (or X to cancel):");
                userInput = Console.ReadLine()?.ToLower().Trim();
                if (userInput != "x")
                {
                    if (!String.IsNullOrEmpty(userInput))
                    {
                        key = userInput;
                    }

                    else
                    {
                        Console.WriteLine("Enter a Valid Key");
                    }
                }
            } while (String.IsNullOrEmpty(userInput) && userInput != "x");

            if (userInput == "x")
            {
                return;
            }

            if (!isEncrypt)
            {
                Console.Write(" You Cipher_Text Please:");
                var plainText = Console.ReadLine();
                if (plainText != null)
                {
                    if (!Input.ValidateBase64(plainText))
                    {
                        Console.WriteLine("Cipher is ONLY base64");
                    }
                    else
                    {
                        CipherJob.Decipher(plainText, key);
                    }
                }
                else
                {
                    Console.WriteLine("CipherText is Invalid!");
                }
            }
            else
            {
                Console.Write("Your Plain_Text please:");
                var plainText = Console.ReadLine();
                if (plainText != null)
                {
                    CipherJob.Encipher(plainText, key);
                }
                else
                {
                    Console.WriteLine("Plaintext is Invalid!");
                }
            }
        }
Пример #2
0
        static void Cesar(bool isEncrypt = true)
        {
            Console.WriteLine("Cesar Cipher");

            // byte per character
            // 0-255
            // 0-127 - latin
            // 128-255 - change what you want
            // ABCD - A 189, B - 195, C 196, D 202
            // unicode
            // AÄÖÜLA❌

            var userInput = "";
            var key       = 0;

            do
            {
                Console.Write("Shift amount please (or X to cancel):");
                userInput = Console.ReadLine()?.ToLower().Trim();
                if (userInput != "x")
                {
                    if (int.TryParse(userInput, out var userValue))
                    {
                        key = userValue % 255;
                        if (key == 0)
                        {
                            Console.WriteLine("not a cipher option, nothing will change!");
                        }
                        else
                        {
                            Console.WriteLine($"Cesar key is: {key}");
                        }
                    }
                }
            } while (key == 0 && userInput != "x");

            if (userInput == "x")
            {
                return;
            }

            if (!isEncrypt)
            {
                Console.Write("Cipher_Text please:");
                var plainText = Console.ReadLine();
                if (plainText != null)
                {
                    if (!Input.ValidateBase64(plainText))
                    {
                        Console.WriteLine("Cipher is ONLY base64");
                    }
                    else
                    {
                        CipherJob.Decipher(plainText, $"{(char)key}");
                    }
                }
                else
                {
                    Console.WriteLine("Cipher_Text is Invalid!");
                }
            }
            else
            {
                Console.Write("Enter The Cipher_Text:");
                var plainText = Console.ReadLine();
                if (plainText != null)
                {
                    CipherJob.Encipher(plainText, $"{(char)key}");
                }
                else
                {
                    Console.WriteLine("Plain_text is Invalid!");
                }
            }
        }