错误消息:
结果回溯(最近一次调用):文件结果第17行,单位为cipher.append(stringList(x*
)+i)
IndexError:列表索引超出范围
我正在制作一个转置密码来加密一个字符串。我将在稍后的解密工作。
我一直在遇到这个错误,但没有幸运地修复它。如果输入文本是'four‘,则输出应为f,u,o,r。
import math
stringToEnc = input("String to encrypt: ")
stringList = list(stringToEnc.replace(" ", ""))
letterCount = len(stringList)
encrypted = []
result = letterCount
for i in range(2, int(math.sqrt(letterCount))+1):
if letterCount % i == 0:
result = i
break
i = 0
while i != letterCount:
for x in range(result):
encrypted.append(stringList[(x*result)+i])
i+=1
print(encrypted)
https://stackoverflow.com/questions/51574592
复制相似问题