How to XOR two strings that contain hex numbers in python?

前端 未结 3 994
轻奢々
轻奢々 2021-01-23 12:07

I have looked for an answer online, but none of them seem to solve my problem in my way (I know, I\'m picky :D).

Here\'s the deal: I am using the string type to store tw

3条回答
  •  轮回少年
    2021-01-23 12:43

    Python can hold your values as numbers.

    See this for proof,

    >>> hex(int(S1, 16))[2:-1] == S1
    True
    

    I'm simply adjusting the string, removing '0x' from the beginning and L from the end.

    For your answer all you need to do is,

    hex(int(S1, 16) ^ int(S2, 16))
    

提交回复
热议问题