Exemple #1
0
        private void DecipherButton_Click(object sender, EventArgs e)
        {
            string inputText = CipherBox.Text;

            if (inputText.Length == 0)
            {
                return;
            }

            if (ShiftAll.Checked)
            {
                PlainBox.Clear();

                for (int i = 1; i < 26; i++)
                {
                    PlainBox.Text += Caesar.Decipher(inputText, i);

                    if (i != 25)
                    {
                        PlainBox.Text += Environment.NewLine;
                    }
                }
            }
            else
            {
                PlainBox.Text = Caesar.Decipher(inputText, (int)ShiftInput.Value);
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Caesar newCaesar = new Caesar();

            Console.WriteLine("Enter your message: ");
            string plainText  = Console.ReadLine();
            string cipherText = newCaesar.Encrypt(plainText);

            Console.WriteLine("Encrypted message is: " + cipherText);
            Console.WriteLine("pres Enter to Decrypt...");
            Console.ReadLine();
            Console.WriteLine("Decrypted message is: " + newCaesar.Decrypt(cipherText));
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("=================");
            Console.WriteLine("CAESAR CIPHER");
            Console.WriteLine("=================");
            Console.WriteLine();
            Console.Write("Enter the string to encrypt :");
            String plainText = Console.ReadLine();
            Console.Write("Enter the integer shift :");
            int shift = Int32.Parse(Console.ReadLine());

            Caesar caesar = new Caesar();
            String cipherText = caesar.Encrypt(plainText, shift);
            Console.WriteLine("Encrypted Text :"+cipherText);
            Console.ReadKey();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("=================");
            Console.WriteLine("CAESAR CIPHER");
            Console.WriteLine("=================");
            Console.WriteLine();
            Console.Write("Enter the string to encrypt :");
            String plainText = Console.ReadLine();

            Console.Write("Enter the integer shift :");
            int shift = Int32.Parse(Console.ReadLine());

            Caesar caesar     = new Caesar();
            String cipherText = caesar.Encrypt(plainText, shift);

            Console.WriteLine("Encrypted Text :" + cipherText);
            Console.ReadKey();
        }
Exemple #5
0
        static void Main(string[] args)
        {
            Caesar caesar = new Caesar(); //宣告caesar物件

            caesar.getMode();             //執行方法
            caesar.getMessage();

            //暴力破解模式,跑回圈(跑當前最大的長度)
            if (caesar.MODE == "b" || caesar.MODE == "brute-force")      //判斷式不可放方法 會出錯
            {
                for (int key = 1; key <= caesar.get_MAX_KEY_SIZE; key++) //會用decrypt是因為要回推
                {
                    Console.WriteLine(key.ToString() + " " + caesar.getTranslateMessage("decrypt", caesar.MESSAGE, key));
                }
            }
            //執行加密or解密模式
            else
            {
                caesar.getKey();                                                                        //沒選擇暴力破解,則會被要求輸入Key
                Console.WriteLine(caesar.getTranslateMessage(caesar.MODE, caesar.MESSAGE, caesar.KEY)); //取得類別內的參數,並處理結果
            }
            Console.Read();                                                                             //等待使用者輸入資料完畢後按ENTER,才繼續執行接在Read()後面的敘述
        }