def sxor(s1,s2):
return ''.join(chr(ord(a) ^ ord(b)) for a,b in zip (s1,s2))
text = sxor('a','a')
text
输出为
\x00
尝试了许多以前回答过的方法,但都无法删除“\x0”,因为只有“0”是必需的答案
这里还有一个例子:
def sxor(s1,s2):
return ''.join(chr(ord(a) ^ ord(b)) for a,b in zip (s1,s2))
text = sxor('1','2')
输出
\x03
我尝试过的事情:
def sxor(s1,s2):
return ''.join(chr(ord(a) ^ ord(b)) for a,b in zip (s1,s2))
text = sxor('1','1')
text.rstrip('\x0')
错误显示:
File "<ipython-input-26-d4905edd1961>", line 6
text.rstrip('\x0')
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-2: truncated \xXX escape
如果我把它写成“\x00”,那么它也会删除所需的部分,并且对任何其他情况都不起作用。我也尝试过使用replace函数。 请帮我解决这个问题
将
chr
替换为str
int
值生成一个字符串作为ascii码。因此chr(0)
表示ascii0
字符,表示为'\x00'
李>int
在本例中)生成字符串str(0)
是'0'
李>示例:
输出:
相关问题 更多 >
编程相关推荐