How to decrypt a string from numbers to characters in C#

1 Answer

0 votes
using System;
using System.Text;

public class Program
{
	private static char convert_to_char_code(string str) {
		int num = int.Parse(str);

		return (char)(num + 96);
	}

	private static string decrypt(string s) {
		StringBuilder sb = new StringBuilder();

		int i = 0;
		while (i < s.Length - 2) {
			char ch;
			if (s[i + 2] == '#') {
				ch = (char)convert_to_char_code(s.Substring(i, 2));
				i += 2;
			}
			else {
				ch = (char)convert_to_char_code(s.Substring(i, 1));
			}

			i++;

			sb.Append(ch);
		}

		return sb.ToString();
	}

	public static void Main(string[] args)
	{
		Console.Write(decrypt("10#1426#25#524#"));
	}
}






/*
run:
 
jadzyex
 
*/

 



answered Jul 16, 2023 by avibootz

Related questions

1 answer 86 views
1 answer 78 views
1 answer 80 views
1 answer 91 views
1 answer 108 views
108 views asked Feb 11, 2024 by avibootz
1 answer 169 views
...