Python 解密密码中的无限循环
Infinite Loop in Python decryption cipher
我不太确定如何防止这种情况永远持续下去,因为我的加密循环看起来很相似,只是它只有一个 if 语句。请帮我解决这个问题。
while i < len(content):
character = content[i]
position = alpha.find(character)
key2 = alpha.find(key[i % len(key)])
key4 = alpha.find(key1[i % len(key1)])
nposition = position - key2 - key4
if nposition > len(alpha)-1:
nposition = nposition - len(alpha)
if nposition < 0:
nposition = nposition + len(alpha)-1
decipher = alpha[nposition]
i = i + i
output = output + decipher
efile = open(filename2, 'w')
efile.write(output)
efile.close()
你死循环的原因可能是这一行:
i = i + i
因为你的 i
可能是用 0
初始化的,所以它永远不会增加。
我猜你刚刚打错了,不用说了......
i = i + 1
... 将解决您的问题。
我不太确定如何防止这种情况永远持续下去,因为我的加密循环看起来很相似,只是它只有一个 if 语句。请帮我解决这个问题。
while i < len(content):
character = content[i]
position = alpha.find(character)
key2 = alpha.find(key[i % len(key)])
key4 = alpha.find(key1[i % len(key1)])
nposition = position - key2 - key4
if nposition > len(alpha)-1:
nposition = nposition - len(alpha)
if nposition < 0:
nposition = nposition + len(alpha)-1
decipher = alpha[nposition]
i = i + i
output = output + decipher
efile = open(filename2, 'w')
efile.write(output)
efile.close()
你死循环的原因可能是这一行:
i = i + i
因为你的 i
可能是用 0
初始化的,所以它永远不会增加。
我猜你刚刚打错了,不用说了......
i = i + 1
... 将解决您的问题。