static bool Integer(int key) { return (key >= 1 && key <= 255); } static char EncryptChar(char ch, int key) { char newCh = ch; int ascii = (int)ch;//find the ascii code of ch int newAscii = ascii ^ key; newCh = Convert.ToChar(newAscii); return newCh; } static string Encrypt(string word, int key) { string newWord = ""; foreach (char ch in word) { char newCh = EncryptChar(ch, key); newWord=newWord + newCh; } return newWord; } static void Main(string[] args) { Console.Write("Enter a phrase: "); string phrase = Console.ReadLine(); Console.Write("Enter a key: "); int key = Convert.ToInt32(Console.ReadLine()); while (!Integer(key)) { Console.Write("Enter a character between 1-255: "); key = Convert.ToInt32(Console.ReadLine()); } string newPhrase = Encrypt(phrase, key); Console.WriteLine("The new phrase is: " + newPhrase); Console.ReadLine(); }