python3遇到的"ord() expected string of length 1, but int found"问题
代码如下:import base64def decode(ciphertext):plaintext = ''ciphertext = base64.b64decode(ciphertext)for i in ciphertext:s = ord(i)-16 ######################s = s^32plaintext += chr(s)r...
·
代码如下:
import base64
def decode(ciphertext):
plaintext = ''
ciphertext = base64.b64decode(ciphertext)
for i in ciphertext:
s = ord(i)-16 ######################
s = s^32
plaintext += chr(s)
return plaintext
cipher = 'XlNkVmtUI1MgXWBZXCFeKY+AaXNt'
flag = decode(cipher)
print(flag)
加了井号的地方在python3下运行会出错而python2不会,原因是因为ord()
这个函数接受的类型是一个长度为1的字符串,而在python3当中传入的i
已经是一个整型数了,直接用i-16
就可以完成操作
具体的讲解可以看这一篇 【Python3】 ord() expected string of length 1, but int found
更多推荐
所有评论(0)