Create a class, StrEncrypt with the following member functions: String EncryptForward (String input) - which will shift the input string by two characters forward - e.g. “a” becomes “c” - “d” becomes “f” - “z” becomes “b” String EncryptBackword(String input) - which will shift the input string by two characters backward - e.g “c” becomes “a” - “d” becomes “b” - “b” becomes “z” Create a windows form to test your class.
Mã: using System; using System.Collections.Generic; using System.Text; namespace StrEncrypt { class Program { static void Main(string[] args) { Console.Out.WriteLine(EncryptForward("azz")); Console.Out.WriteLine(EncryptBackward("azz")); } static String EncryptForward(String input) { char[] charArray = input.ToCharArray(); for (int i = 0; i < charArray.Length; i++) { if (charArray[i] > 'x') { charArray[i] = (char)(charArray[i] + 2 - 26); } else { charArray[i] = (char)(charArray[i] + 2); } } return new string(charArray); } static String EncryptBackward(String input) { char[] charArray = input.ToCharArray(); for (int i = 0; i < charArray.Length; i++) { if (charArray[i] < 'c') { charArray[i] = (char)(charArray[i] - 2 + 26); } else { charArray[i] = (char)(charArray[i] - 2); } } return new string(charArray); } } } Code xử lý chính nó vầy, còn phần code cái GUI để test thì bạn làm hen, không khó đâu. Srry chuơng trình code ẩu trong 2 phút, nhiều hard-codded pro đừng vào xét nét nha.