1

I have to decode value '9DAFF2834DDD73C18D79E31DE22F0D49DF13E525D3FFAE599530BECCD1B916FF' to hex in python:

For this I am doing

>>> import binascii
>>>
>>> binascii.unhexlify('9DAFF2834DDD73C18D79E31DE22F0D49DF13E525D3FFAE599530BECCD1B916FF')
>>>'\x9d\xaf\xf2\x83M\xdds\xc1\x8dy\xe3\x1d\xe2/\rI\xdf\x13\xe5%\xd3\xff\xaeY\x950\xbe\xcc\xd1\xb9\x16\xff'

But, postgres is giving value as:

>>> db=> select decode('9DAFF2834DDD73C18D79E31DE22F0D49DF13E525D3FFAE599530BECCD1B916FF','hex') as sha;

The output is:

>>> \235\257\362\203M\335s\301\215y\343\035\342/\015I\337\023\345%\323\377\256Y\2250\276\314\321\271\026\377

Is there any equivalent in Python which will give same result as in Postgres (the Postgres output is a bytea)?

1 Answer 1

1

Not to be rude, but they're exactly the same. One is octal, the other hexadecimal.

>>> '\235\257\362\203M\335s\301\215y\343\035\342/\015I\337\023\345%\323\377\256Y\2250\276\314\321\271\026\377'
'\x9d\xaf\xf2\x83M\xdds\xc1\x8dy\xe3\x1d\xe2/\rI\xdf\x13\xe5%\xd3\xff\xaeY\x950\xbe\xcc\xd1\xb9\x16\xff'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.