Last active
October 12, 2015 10:32
-
-
Save ivanhjc/1776bd202ff3ae077950 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 C8Ex12CaptainCrunch2 { | |
public static char convert(String dict, int j) { | |
if (j < 13) { | |
return dict.charAt(j+13); | |
} else { | |
return dict.charAt(j-13); | |
} | |
} | |
public static String decode(String s) { | |
String d = "abcdefghijklmnopqrstuvwxyz"; //dict.indexOf(n) == 13 | |
String D = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
String x = ""; | |
int i = 0; | |
int n = s.length(); | |
while (i < n) { | |
if (s.charAt(i) == ' ') { | |
x = x + " "; | |
} else { | |
int j = d.indexOf(s.charAt(i)); | |
if (j != -1) { | |
x = x + convert(d, j); | |
} else { | |
j = D.indexOf(s.charAt(i)); | |
x = x + convert(D, j); | |
} | |
} | |
i = i + 1; | |
} | |
return x; | |
} | |
public static void main(String[] args) { | |
String s = "faiodfja"; | |
System.out.println(decode(s)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment