Liuciferis
We'll bang, OKAY?
Hello,
I am writing a Java server emulator for Tibia and I having some problems with XTEA encryption.
My encyption:
Encryption result:
As you can see, it encrypts only ~14 bytes at the beginning and that's all.
I have no idea why it works like that. Maybe someone could answer me?
I am writing a Java server emulator for Tibia and I having some problems with XTEA encryption.
My encyption:
Code:
public static byte[] encrypt(byte[] bytes, long[] key) throws IOException
{
ByteArrayOutputStream st = new ByteArrayOutputStream();
st.write(bytes);
long delta = 0x61C88647;
// the message must be a multiple of 8
int paddingBytes = bytes.length & 7;
if (paddingBytes != 0) {
int count = 8 - paddingBytes;
for (int i = 0; i < count; i++)
st.write(0x33);
}
bytes = st.toByteArray();
int messageLength = bytes.length / 4;
int readPos = 0;
while (readPos < messageLength)
{
long v0 = bytes[readPos], v1 = bytes[readPos + 1];
long sum = 0;
for (int i = 32; --i >= 0;)
{
v0 += ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + key[(int) (sum & 3)]);
sum -= delta;
v1 += ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + key[(int) ((sum >> 11) & 3)]);
}
bytes[readPos++] = (byte) v0;
bytes[readPos++] = (byte) v1;
}
return bytes;
}
Encryption result:
Code:
Normal:
35 0 14 E 0 31 A 48 65 6C 6C 6F 20 77 6F 72 6C 64 21 64 1 0 5 0 41 75 72 65 61 9 0 31 32 37 2E 30 2E 30 2E 31 4 1C 0 1 0 6 0 57 64 65 6D 6F 6E FF FF
Encrypted:
AB A3 92 81 FC 31 F3 F3 AF 85 C3 D7 C3 24 6F 72 6C 64 21 64 1 0 5 0 41 75 72 65 61 9 0 31 32 37 2E 30 2E 30 2E 31 4 1C 0 1 0 6 0 57 64 65 6D 6F 6E FF FF 33
As you can see, it encrypts only ~14 bytes at the beginning and that's all.
I have no idea why it works like that. Maybe someone could answer me?