I have a string as follows:
This is a generic solution, this a very fast algorithm that can handle any string in any encoding.
public class Translator {
private static final String key = "Zx" + Math.log(2) / 3;
public static String obfuscate(String s) {
char[] result = new char[s.length()];
for (int i = 0; i < s.length(); i++) {
result[i] = (char) (s.charAt(i) + key.charAt(i % key.length()));
}
return new String(result);
}
public static String unobfuscate(String s) {
char[] result = new char[s.length()];
for (int i = 0; i < s.length(); i++) {
result[i] = (char) (s.charAt(i) - key.charAt(i % key.length()));
}
return new String(result);
}
}
String obfuscate = Translator.obfuscate("Hi there");
System.out.println(obfuscate + " - " + Translator.unobfuscate(obfuscate));
Output:
¢áP¢£ - Hi there