private static string EncryptWithKey(string text, char key) { char[] alphabet = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; char[] selectedCipher = ChooseArray(key); string encryptedString = String.Empty; foreach (char character in text) { if (!char.IsLetter(character)) { encryptedString += character; } else if (char.IsUpper(character)) { char[] upperAlpha = alphabet.ArrayToUpper(); char[] upperSelectedCipher = selectedCipher.ArrayToUpper(); //int index = alphabet.ToString().IndexOf(character); int index = Array.IndexOf(upperAlpha, character); encryptedString += upperSelectedCipher[index]; } else { int index = Array.IndexOf(alphabet, character); encryptedString += selectedCipher[index]; } } return(encryptedString); }