-1

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.

1
  • What's the problem with struct.pack? Commented Oct 25, 2012 at 9:52

1 Answer 1

7

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'
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.