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
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)