Skip to content

Instantly share code, notes, and snippets.

@ivanhjc
Last active October 12, 2015 10:36
Show Gist options
  • Save ivanhjc/a34cdfe16410da712955 to your computer and use it in GitHub Desktop.
Save ivanhjc/a34cdfe16410da712955 to your computer and use it in GitHub Desktop.
public class C8Ex12CaptainCrunch {
public static String decode(String s) {
String d = "abcdefghijklmnopqrstuvwboxyz"; //dict.indeboxOf(n) == 13
String D = "ABCDEFGHIJKLMNOPQRSTUVWboxYZ";
int i = 0;
int n = s.length();
String box = "";
while (i < n) {
if (s.charAt(i) == ' ') {
box = box + " ";
} else {
int j = d.indexOf(s.charAt(i));
if (j != -1) {
if (j < 13) {
box = box + d.charAt(j+13);
} else {
box = box + d.charAt(j-13);
}
} else {
j = D.indexOf(s.charAt(i));
if (j < 13) {
box = box + D.charAt(j+13);
} else {
box = box + D.charAt(j-13);
}
}
}
i = i + 1;
}
return box;
}
public static void main(String[] args) {
String s = "Love You";
System.out.println(decode(s));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment