Reputation: 91
I'm trying to convert a string to hex on Python but I made something wrong.
On this site: http://string-functions.com/string-hex.aspx I got the follow converted code
"60b6e02de9a758dbf43c0756f59e1d6558b46b462865a3b66d7922e8a2962175"
which works, but on my Python script I got
"60c2b6c3a02dc3a9c2a758c39bc3b43c0756c3b5c5be1d6558c2b46b462865c2a3c2b66d7922c3a8c2a2e280932175".
The string on question is:
`¶à-é§XÛô<VõžeX´kF(e£¶my"袖!u
And the Python script used:
import binascii
x = '`¶à-é§XÛô<VõžeX´kF(e£¶my"袖!u'
a = x.encode('utf-8')
hex_bytes = binascii.hexlify(a)
print(hex_bytes)
Upvotes: 1
Views: 282
Reputation: 880707
As Yann Vernier suggested, the webpage appears to be encoding with cp1252 before hexlifying:
import binascii
x = u'`¶à-é§XÛô<VõžeX´kF(e£¶my"袖!u'
hex_bytes = binascii.hexlify(x.encode('cp1252'))
print(hex_bytes)
yields
60b6e02de9a758dbf43c56f59e6558b46b462865a3b66d7922e8a2962175
Upvotes: 5