Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中两个十六进制字符串的异或_Python_Bitwise Operators - Fatal编程技术网

python中两个十六进制字符串的异或

python中两个十六进制字符串的异或,python,bitwise-operators,Python,Bitwise Operators,我有两个字符串值与char和hex等价。如何对这两个字符串进行异或运算,以使结果的格式为\x00\x01\x 其中: String1和String2与相应的ASCII值相等 输入: 我使用下面的方法来查找XOR值 我想你想的是: String1 = "ABC" String2 = "\x72\x61\x74" result = "".join(chr(c1 ^ c2) for c1, c2 in zip(map(ord, String1), map(ord, String2))) print(r

我有两个字符串值与char和hex等价。如何对这两个字符串进行异或运算,以使结果的格式为\x00\x01\x

其中: String1和String2与相应的ASCII值相等

输入:

我使用下面的方法来查找XOR值


我想你想的是:

String1 = "ABC"
String2 = "\x72\x61\x74"
result = "".join(chr(c1 ^ c2) for c1, c2 in zip(map(ord, String1), map(ord, String2)))
print(result)
# prints "3#7"
或者,如果要打印十六进制表示,可以:

String1 = "ABC"
String2 = "\x72\x61\x74"
result = "".join("\\x{:02x}".format(c1 ^ c2) for c1, c2 in zip(map(ord, String1), map(ord, String2)))
print(result)
# prints "\x33\x23\x37"
hex(ord('A')) ^ '\x72' = ??
hex(ord('B')) ^ '\x61' = ??
hex(ord('C')) ^ '\x74' = ??
String1 = "ABC"
String2 = "\x72\x61\x74"
result = "".join(chr(c1 ^ c2) for c1, c2 in zip(map(ord, String1), map(ord, String2)))
print(result)
# prints "3#7"
String1 = "ABC"
String2 = "\x72\x61\x74"
result = "".join("\\x{:02x}".format(c1 ^ c2) for c1, c2 in zip(map(ord, String1), map(ord, String2)))
print(result)
# prints "\x33\x23\x37"