I’m trying to convert a string of characters into each characters decimal form and seperating them with a symbol that is chosen at random and then after that’s converted, seperating the decimal numbers from the string and then adding 1 to those numbers and then converting them back into ASCII characters. Here’s what I have so far but it keeps saying invalid input format with ‘int.Parse’:
public string Encode(string data, out string asciiString) {
char[] dataArray = data.ToCharArray();
string[] symb = {"@","#","$","%","&"};
Random rnd = new Random();
string newData = "";
for(int i = 0; i < dataArray.Length; i++) {
newData += (((int)dataArray[i] + 1) + symb[rnd.Next(0, 5)].ToString()); // add 1 to the decimal and then add symbol
}
asciiString = ConvertToAscii(newData);
return newData;
}
public string ConvertToAscii(string data) {
string[] tokens = data.Split('@', '#', '$', '%', '&');
data = data.TrimEnd('@', '#', '$', '%', '&');
string returnString = "";
for(int i = 0; i < tokens.Length; i++){
int num = int.Parse(tokens[i]);
returnString += (char)num;
}
return returnString;
}
Here’s an example:
Normal: “Hello”
converted to decimal with symbols: 72$101&108#108@111%
converted to ascii (without symbols and adding 1): Ifmmp (I had to do it with an ascii table)
You should switch these lines around so you can avoid calling Parse with an empty string.