Here’s a programming challenge I have been baffled on:
public class CrackTheCode {
public static void main(String[] args) {
// Test the masher
String testString = "One Team, One Goal, One Web.";
if (Masher.unmash(Masher.mash(testString)).equals(testString)) {
System.out.println("OK");
} else {
System.out.println("Error");
}
}
static class Masher {
static String mash(String s) {
byte[] bytes = s.getBytes();
byte[] mashed = new byte[bytes.length];
for (int i = 0; i < bytes.length; i++) {
mashed[i] = (byte) ~bytes[i];
}
return new String(mashed);
}
static String unmash(String s) {
//TODO
return null;
}
}
}