Reputation: 3233
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.
Upvotes: 1
Views: 1975
Reputation: 94058
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))
Upvotes: 1