public Rot13Text GetRot13Text(Rot13Text rText)
        {
            foreach (char plnChar in rText.PlainText)
            {
                rText.StrBuild.Append(CipherService.GetCipherLetter(plnChar, rText.Key));
            }

            rText.CipherText = rText.StrBuild.ToString();
            return(rText);
        }
Exemplo n.º 2
0
        public static void Index()
        {
            #region initialize
            Initialize();

            string plainTxt, keyWord;
            int    key;
            bool   isValid;
            #endregion

            #region input
            Console.WriteLine("Enter plaintext:");
            plainTxt = Console.ReadLine();

            isValid = false;
            key     = 0;
            while (!isValid)
            {
                Console.WriteLine("Enter a positive integer as the key for the Caesar cipher:");
                var input = Console.ReadLine();
                isValid = int.TryParse(input, out key) && key > 0;
            }

            isValid = false;
            keyWord = "";
            while (!isValid)
            {
                Console.WriteLine("Enter a key word for the Vigenere cipher:");
                keyWord = Console.ReadLine();
                isValid = Regex.IsMatch(keyWord, @"^[a-zA-Z]+$");;
            }
            #endregion

            #region get ciphers
            Rot13Text    rot13Text    = Rot13Controller.GetRot13Text(new Rot13Text(plainTxt));
            CaesarText   caesarText   = CaesarController.GetCaesarText(new CaesarText(plainTxt, key));
            VigenereText vigenereText = VigenereController.GetVigenereText(new VigenereText(plainTxt, keyWord));
            #endregion

            #region output
            Console.WriteLine(string.Format("\nROT13:\n" + rot13Text.CipherText));
            Console.WriteLine(string.Format("\nCaesar:\n" + caesarText.CipherText));
            Console.WriteLine(string.Format("\nVigenere:\n" + vigenereText.CipherText));
            #endregion
        }