I have the two inverse inverse functions:
public static BigInteger stringToBig(String message) {
StringBuilder sb = new StringBuilder();
for (char c : message.toCharArray()) {
sb.append((int)c);
}
return new BigInteger(sb.toString());
}
public static String bigStringToString(String string) {
StringBuilder result = new StringBuilder();
for (int x = (string.length() % 3 - 3) % 3; x < string.length(); x += 3) {
int chr = Integer.parseInt(string.substring(Math.max(x, 0), x + 3));
result.append(Character.toString((char) (chr)));
}
return result.toString();
}
My goal is to take the string from
"This is my message"
Convert it to "8410410511532105115321091213210910111511597103101"
and then convert it back to "This is my message"
I've tried the following but get "????is?[ÕÒ?o??ge" back as an output from bigStringToString
String text = String.valueOf(stringToBig("This is my message"));
System.out.println(text);
System.out.println(bigStringToString(text));
What's wrong with my conversion back?
charis ASCII? It's actually UTF-16.