how to do from hex of this…
- User
how to do from hex of this 1f397b272722252c140a253f7a140f78293e0c0c2e19143f39222820311419142d3e256a and XOR with 4B hex in Python ? result shoud be ascii text. not hex
- Assistant
You can XOR the hex string with
0x4Band then convert it back to ASCII text in Python. Here's an example of how to do it:hex_data = "1f397b272722252c140a253f7a140f78293e0c0c2e19143f39222820311419142d3e256a" xor_value = 0x4B # Convert the hex string to bytes data_bytes = bytes.fromhex(hex_data) # XOR each byte with 0x4B and convert it to a bytes object result_bytes = bytes(byte ^ xor_value for byte in data_bytes) # Convert the resulting bytes object to a string result_string = result_bytes.decode('ascii') print(result_string)Make sure that the output of the XOR operation is valid ASCII. If any value after XORing falls outside the ASCII range (0-127), you would get an error when trying to
.decode('ascii'). If you're expecting only printable ASCII characters, you may filter or handle the cases that fall outside the printable ASCII range (0x20to0x7E). If the output is in extended ASCII (up to 255), you could replace.decode('ascii')with.decode('latin-1')which covers the full range of single byte characters.