using System; using System.Collections.Generic; namespace ConsoleApp2 { class Program { private static string Encrypt(string a) { List list = new List(a); for (int i = 0; i < a.Length; i++) { if (i % 2 == 0) { if (Char.IsUpper(list[i])) { int ascii = (Convert.ToInt32(list[i]) - 65 - 1); if (ascii < 0) ascii += 26; list[i] = Convert.ToChar(ascii + 65); } else if (Char.IsLower(list[i])) { int ascii = (Convert.ToInt32(list[i]) - 97 - 1) ; if (ascii < 0) ascii += 26; list[i] = Convert.ToChar(ascii + 97); } } else { if(Char.IsUpper(list[i])) { int ascii = (Convert.ToInt32(list[i]) - 65 + 3) % 26; list[i] = Convert.ToChar(ascii + 65); } else if(Char.IsLower(list[i])) { int ascii = (Convert.ToInt32(list[i]) - 97 + 3) % 26; list[i] = Convert.ToChar(ascii + 97); } } } string b = new string(list.ToArray()); return b; } private static string Decrypt(string a) { List list = new List(a); for (int i = 0; i < a.Length; i++) { if (i % 2 == 0) { if (Char.IsUpper(list[i])) { int ascii = (Convert.ToInt32(list[i]) - 65 + 1) % 26; list[i] = Convert.ToChar(ascii + 65); } else if (Char.IsLower(list[i])) { int ascii = (Convert.ToInt32(list[i]) - 97 + 1) % 26; list[i] = Convert.ToChar(ascii + 97); } } else { if (Char.IsUpper(list[i])) { int ascii = (Convert.ToInt32(list[i]) - 65 - 3); if (ascii < 0) ascii += 26; list[i] = Convert.ToChar(ascii + 65); } else if (Char.IsLower(list[i])) { int ascii = (Convert.ToInt32(list[i]) - 97 - 3); if (ascii < 0) ascii += 26; list[i] = Convert.ToChar(ascii + 97); } } } string b = new string(list.ToArray()); return b; } static void Main(string[] args) { string x = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; string y = Encrypt(x); string z = Decrypt(y); Console.WriteLine(x); Console.WriteLine(y); Console.WriteLine(z); Console.Write("Enter a TEXT to encrypt : "); string txt = Console.ReadLine(); y = Encrypt(txt); z = Decrypt(y); Console.WriteLine("Encryption TEXT : " + y); Console.WriteLine("Decryption The Encrypted TEXT : " + z); } } }