Question

I always fail with the decrypting of a RC4 encrypted object. My key has to be the MD5-Hash of this hex string:

00 00 00 01 3e 2a 5b 71 00 00 03 a0

What i tried was to convert that hex string to ascii and calculate afterwards the MD5 hash of it, but it seems like my key is always wrong. I think there is a problem because some of the hex values are control characters, but how is then the correct way to calculate the MD5 of this hex string ? What i thought of was something like this:

from Crypto.Cipher import ARC4
from Crypto.Hash import MD5


def hexToAscii(hex_string):
    return ''.join([chr(int(''.join(c), 16)) for c in zip(hex_string[0::2],hex_string[1::2])])

def main():
    hex_string = '000000013e2a5b71000003a0'

    # Key for Decryption
    myKey = MD5.new(hexToAscii(hex_string)).hexdigest()

    print 'hexToAscii(hex_string): %s' % hexToAscii(hex_string)

    #open('myfile','wb').write(ARC4.new(hexToAscii(myKey)).decrypt(hexToAscii(CIPHER_TEXT)))

if __name__ == '__main__':
    main()
Was it helpful?

Solution

The main function prints hexToAscii(hex_string) instead of myKey.

BTW, you'd better to use binascii.unhexlify instead of hexToAscii. And you can use hashlib module to calculate md5.

>>> import hashlib
>>> import binascii
>>> hex_string = '000000013e2a5b71000003a0'
>>> hashlib.md5(binascii.unhexlify(hex_string)).hexdigest()
'6afebf522c531575e96d6814be816c7c'

OTHER TIPS

Use hashlib and binascii from Python standard lib, no conversion to ASCII involved:

import binascii
import hashlib

base = binascii.unhexlify("000000013e2a5b71000003a0")
key = hashlib.md5(base).digest()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top