pack("H*", '0rdR-0PrdK')
produces garbage.
Thats true, but this garbage were used as secret key in encryption algorithm. It was possible to decrypt when you used the same garbage.
I was really pressed on time so i did it this way:
- I found packed(H*...) value of every character in Perl
- encode them with Base64
- decode hardcoded values in Java
private static final String[] possibleChars = {"0`", "`0", "0~", "~0", "0!", "!0", "0@", "@0", "0#", "#0", "0$", "$0", "0%", "%0", "0^", "^0",
"0&", "&0", "0*", "*0", "0(", "(0", "0)", ")0", "0-", "-0", "0_", "_0", "0=", "=0", "0+", "+0", "0[", "[0", "0{", "{0",
"0]", "]0", "0}", "}0", "0\\", "\\0", "0|", "|0", "0;", ";0", "0:", ":0", "0'", "'0", "0\"", "\"0", "0,", ",0", "0<",
"<0", "0.", ".0", "0>", ">0", "0/", "/0", "0?", "?0", "0a", "a0", "0b", "b0", "0c", "c0", "0d", "d0", "0e", "e0", "0f",
"f0", "0g", "g0", "0h", "h0", "0i", "i0", "0j", "j0", "0k", "k0", "0l", "l0", "0m", "m0", "0n", "n0", "0o", "o0", "0p",
"p0", "0q", "q0", "0r", "r0", "0s", "s0", "0t", "t0", "0u", "u0", "0v", "v0", "0w", "w0", "0x", "x0", "0y", "y0", "0z",
"z0", "00", "00", "01", "10", "02", "20", "03", "30", "04", "40", "05", "50", "06", "60", "07", "70", "08", "80", "09", "90"};
private static final String[] base64codes = {"AA==", "AA==", "Dg==", "4A==", "AQ==", "EA==", "AA==", "AA==", "Aw==", "MA==", "BA==",
"QA==", "BQ==", "UA==", "Dg==", "4A==", "Bg==", "YA==", "Cg==", "oA==", "CA==", "gA==", "CQ==", "kA==", "DQ==", "0A==",
"Dw==", "8A==", "DQ==", "0A==", "Cw==", "sA==", "Cw==", "sA==", "Cw==", "sA==", "DQ==", "0A==", "DQ==", "0A==", "DA==",
"wA==", "DA==", "wA==", "Cw==", "sA==", "Cg==", "oA==", "Bw==", "cA==", "Ag==", "IA==", "DA==", "wA==", "DA==", "wA==",
"Dg==", "4A==", "Dg==", "4A==", "Dw==", "8A==", "Dw==", "8A==", "Cg==", "oA==", "Cw==", "sA==", "DA==", "wA==", "DQ==",
"0A==", "Dg==", "4A==", "Dw==", "8A==", "AA==", "AA==", "AQ==", "EA==", "Ag==", "IA==", "Aw==", "MA==", "BA==", "QA==",
"BQ==", "UA==", "Bg==", "YA==", "Bw==", "cA==", "CA==", "gA==", "CQ==", "kA==", "Cg==", "oA==", "Cw==", "sA==", "DA==",
"wA==", "DQ==", "0A==", "Dg==", "4A==", "Dw==", "8A==", "AA==", "AA==", "AQ==", "EA==", "Ag==", "IA==", "Aw==", "MA==",
"AA==", "AA==", "AQ==", "EA==", "Ag==", "IA==", "Aw==", "MA==", "BA==", "QA==", "BQ==", "UA==", "Bg==", "YA==", "Bw==",
"cA==", "CA==", "gA==", "CQ==", "kA=="};
private static void initializeHashMap() {
for (int i = 0; i < possibleChars.length; i++) {
hashMap.put(possibleChars[i], base64codes[i]);
}
}
public static byte[] h16pack(String s) {
String str = s.toLowerCase();
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) (Base64.decode(hashMap.get(str.charAt(i) + "0"))[0]
+ Base64.decode(hashMap.get("0" + str.charAt(i + 1)))[0]);
}
return data;
}
not elegant, but it works