Using the PHP pack() function, I have converted a string into a binary hex representation:
pack('H*', $SECURE_SECRET)
How can I get the same result in Python?
I tried struct.pack
, but the result is not the same.
Using the PHP pack() function, I have converted a string into a binary hex representation:
pack('H*', $SECURE_SECRET)
How can I get the same result in Python?
I tried struct.pack
, but the result is not the same.
pack('H*', $value)
converts hexadecimal numbers to binary:
php> = pack('H*', '41424344')
'ABCD'
In Python, you can use binascii.unhexlify
to get the same result:
>>> from binascii import unhexlify
>>> unhexlify('41424344')
>>> 'ABCD'