我在这里遇到一个错误,我想知道你们中是否有人能看到我哪里出错了。我几乎是 python 的初学者,看不到我哪里出错了。
temp = int(temp)^2/key
for i in range(0, len(str(temp))):
final = final + chr(int(temp[i]))
“temp”由数字组成。“钥匙”也是由数字组成的。这里有什么帮助吗?
首先,您定义temp
为一个整数(在 Python 中,^
也不是“幂”符号。您可能正在寻找**
):
temp = int(temp)^2/key
但后来你把它当作一个字符串:
chr(int(temp[i]))
^^^^^^^
是否有另一个名为 的字符串temp
?或者您是否希望提取第i
th 位,可以这样做:
str(temp)[i]
final = final + chr(int(temp[i]))
在那一行temp仍然是一个数字,所以使用str(temp)[i]
编辑
>>> temp = 100 #number
>>> str(temp)[0] #convert temp to string and access i-th element
'1'
>>> int(str(temp)[0]) #convert character to int
1
>>> chr(int(str(temp)[0]))
'\x01'
>>>