but i've had no luck ;( (the code is orignally borrowed/stolen but I have the credits in the sourcefile)
Can anyone help me to crack this nut, what am I doing wrong?
Code: Select all
static String decode(String lock, byte xorKey)
{
StringBuffer key = new StringBuffer();
int lockLength = lock.length();
System.out.println(lockLength);
// The first byte is handled separately from the first, last,
// and second to last bytes.
char a1 = (char)lock.charAt(0);
char a2 = (char)lock.charAt(lockLength - 1);
char a3 = (char)lock.charAt(lockLength - 2);
// Xor them all and swap nibbles.
//char char1 = (char) (a1 ^ xorKey);
for(int i = 1; i < lockLength;i++ )
{
key.append((char)(lock.charAt(i) ^ lock.charAt(i-1)) );
}
int char1 = a1 ^ a2 ^ a3 ^5;
key.insert(0,(char)char1);
// And do the rest of the bytes.
for (int i = 0; i < lockLength; i++)
{
// Each key byte is the xor of the corresponding lock byte
// and the one before it, nibble-swapped (that's why the
// first is special).
char a5 = (char)key.charAt(i);
//char a6 = (char)key.charAt(i-1);
//char char3 = (char) (a5 ^ a6);
char char4 = (char)((a5 << 4) & 240 | (a5 >> 4) & 15);
key.append((char)char4);
}
// Key has the right bytes, but it needs to have certain
// characters escaped.
return escapeChars(key);
}
static String escapeChars(StringBuffer key)
{
StringBuffer encoded = new StringBuffer();
for (int i = 0; i < key.length(); i++)
{
// You might think we'd have to add the '/' escape character
// to this list. Oh well.
int a = (int)key.charAt(i);
if (a == 126 || // '~'
a == 124 || // '|'
a == 96 || // '`'
a == 36 || // '$'
a == 5 || // '^E'
a == 0) // NUL
{
encoded.append("/%DCN");
// Ensure we have 3 digits.
if (a < 100)
encoded.append("0");
if (a < 10)
encoded.append("0");
encoded.append(a); // As a string integer
encoded.append("%/");
} else {
encoded.append((char)a); // No transformation.
}
}
return encoded.toString();
}