Last active
October 12, 2015 10:36
-
-
Save ivanhjc/a34cdfe16410da712955 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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