Answer the question
In order to leave comments, you need to log in
How to get unicode string from hex string?
There is a hex string in the database. It needs to be decrypted.
The string is big, I'm only attaching part of it "0x308218D806092A"
if __name__ == "__main__":
# sReverseHex = reverse_str(s[2:])
sByte = bytearray.fromhex(s[2:])
# print (chardet.detect(sByte ))
sResult = sByte.decode("utf-16-be")
print(sResult)
code results in UnicodeDecodeError: 'utf16' codec can't decode bytes in position 1326-1327: illegal UTF-16 surrogate Different
encodings tried. chardet.detect(sByte) gave the result
{'confidence': 0.0, 'language': None, 'encoding': None}
Answer the question
In order to leave comments, you need to log in
There is a standard bas64 module. It contains the b16encode and b16decode functions.
This is the correct way to encode and decode a string to and from hex.
If you did it differently, then you need to figure out how it was coded.
That's why I asked where the string comes from and asked for an example larger than what you wrote.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question