我正在为计算机科学课程创建一个项目,在该课程中创建堆叠密码。我正在使用复制到剪贴板功能,以允许下一个密码更改消息。我遇到了第二个密码的问题,这是一个替换密码。当我运行它时,它返回“无法将'int'隐式转换为str”。我尝试过使用 str(message) 但这不起作用,并且我尝试过更改代码。我不擅长python,所以如果是一个简单的错误,请告诉我。我能做些什么来帮助解决这些错误。我曾考虑将消息更改为列表,但我该怎么做?
这是我正在使用的代码:
def main():
myMessage = pyperclip.paste()
myKey = 8
ciphertext = encryptMessage(myKey, myMessage)
print(ciphertext + '|')
pyperclip.copy(ciphertext)
def encryptMessage(key, message):
ciphertext = [''] * key
str(ciphertext)
for col in range(key):
pointer = col
while pointer < len(message):
ciphertext[col] += message[pointer]
pointer += key
return ''.join(ciphertext)
print(ciphertext)
这是我收到的错误:
Traceback (most recent call last):
File "I:\project\transpositionEncrypt.py", line 38, in <module>
Enc()
File "I:\project\transpositionEncrypt.py", line 37, in Enc
main()
File "I:\project\transpositionEncrypt.py", line 10, in main
ciphertext = encryptMessage(myKey, myMessage)
File "I:\project\transpositionEncrypt.py", line 27, in encryptMessage
ciphertext[col] += message[pointer]
TypeError: Can't convert 'int' object to str implicitly