1

I am trying to decrypt data which was encrypted using XTEA algorithm. I have the 128-bit key.

All the implementations I checked so far accept the key as a 16 char string (ASCII). However, my key is in hexadecimal format (32 chars) or 4 DWORDs.

Is there an implementation where I can specify the key in hex format to decrypt the data?

I checked a few implementations online and for example here:

https://code.google.com/p/zzt-code-base/source/browse/trunk/src/python/xtea.py

It will require source code to be modified to decrypt using the key in hexadecimal format.

specifically in the function, xtea_decrypt() in the line:

k = struct.unpack(endian+"4L",key)

what modification do I need to make so that I can specify the key in hexadecimal format?

Also, if there is an existing implementation which can accept key in hex format, that will help.

Neon Flash
  • 3,113
  • 12
  • 58
  • 96
  • Good question. I won't answer because I am not a python expert. It seems that older versions of python confused bytes with characters (as many languages did). What you want to do is to specify the key in *bytes* not hexadecimal characters. You can do the hexadecimal to bytes conversion - probably just "hexstring".decode("hex") - outside of the library. Modern crypto operates on bytes, not on strings. – Maarten Bodewes Sep 08 '13 at 12:46

1 Answers1

1

Modern cryptography works on bytes, not on strings. This includes hexadecimal strings. So to feed the function a key specified in hexadecimals, please first call binascii.unhexlify(hexString).

In the code you are pointing to you can for instance replace the default iv parameter assignment with iv=binascii.unhexlify('0000000000000000').

So this works on my machine (as a Python noob):

key = binascii.unhexlify('00000000000000000000000000000000')
iv = binascii.unhexlify('0000000000000000')
print data == x.xtea_cbc_decrypt(key, iv, x.xtea_cbc_encrypt(key, iv, data))
Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263