1
Reply

String encryption in c# . You have the original string msg=ABCD .She encrypts the string by replacing each character by 2nd next character.

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace ConsoleApplication2 {class Program{static void Main(string[] args){string Val = Convert.ToString(Console.ReadLine());int Val2 = Convert.ToInt32(Console.ReadLine());string[] a = Val.Select(c => c.ToString()).ToArray();int[] arr = new int[a.Length];for (int i = 0; i < a.Length; i++){string s = a[i].ToString(); byte[] bytes = Encoding.ASCII.GetBytes(s);int result = Convert.ToInt32(bytes[0]);arr[i] = result + Val2;}string[] str = new string[arr.Length];for (int j = 0; j < arr.Length; j++){char c = Convert.ToChar(arr[j]); str[j] =Convert.ToString(c);}string result1 = ConvertStringArrayToString(str);Console.WriteLine("Your Result is:- " + result1);Console.ReadLine();}static string ConvertStringArrayToString(string[] array){ StringBuilder builder = new StringBuilder();foreach (string value in array){builder.Append(value); }return builder.ToString();}} }Input is ABCD 4 Output EFGH