Skip to content

Instantly share code, notes, and snippets.

@lgo
Last active December 16, 2015 17:00
Show Gist options
  • Save lgo/5467631 to your computer and use it in GitHub Desktop.
Save lgo/5467631 to your computer and use it in GitHub Desktop.
ECOO Split Code Decryption Solution
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
public class Sol1 {
public static void main (String[] args) throws Exception {
BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
BufferedWriter bw = new BufferedWriter(new FileWriter("out1.txt"));
char[] a1 = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P'};
char[] a2 = {'Q','R','S','T','U','V','W','X','Y','Z','K','L','M','N','O','P'};
for (int i = 0; i < 1; i++) {
String encrypt = br.readLine();
String dealpha = "";
for (int x = 0; x < encrypt.length(); x++) {
for (int n = 0; n < a1.length; n++) {
if (encrypt.charAt(x) == a1[n] || encrypt.charAt(x) == a2[n]) {
dealpha += Integer.toHexString(n);
break;
}
}
}
for (int x = dealpha.length() - 1; x > 0; x--){
int curr = Integer.parseInt(dealpha.charAt(x) + "", 16);
int last = Integer.parseInt(dealpha.charAt(x - 1) + "", 16);
if (curr < last) {
curr = Integer.parseInt("1" + dealpha.charAt(x), 16);
}
char[] temp = dealpha.toCharArray();
temp[x] = Integer.toHexString(curr - last).toCharArray()[0];
dealpha = "";
for (char c : temp) {
dealpha += c;
}
}
//Silly hack to get to ACSII :/
String out = "";
for (int x = 0; x < dealpha.length(); x+=2) {
int temp = Integer.parseInt(Character.toString(dealpha.charAt(x)) + Character.toString(dealpha.charAt(x + 1)), 16);
out += (char) temp;
}
System.out.println(out);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment