Beispiel #1
0
        public VigenereText GetVigenereText(VigenereText vText)
        {
            List <int> shiftVals = CipherService.GetShiftVals(vText.KeyWord);
            int        i         = 0;

            while (i < vText.PlainText.Length)
            {
                for (int j = 0; j < shiftVals.Count; j++)
                {
                    if (i >= vText.PlainText.Length)
                    {
                        break;
                    }
                    else
                    {
                        vText.StrBuild.Append(CipherService.GetCipherLetter(
                                                  vText.PlainText[i],
                                                  shiftVals[j]));
                    }

                    i++;
                }
            }

            vText.CipherText = vText.StrBuild.ToString();
            return(vText);
        }
Beispiel #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
        }