python将文本文件加密后输出_Python:将Casear密码和柱状转置密码的加密输出写入.txt文件...
我希望這很容易解決 . 我使用Python在Windows Powershell中獲得的錯誤如下:
Traceback (most recent call last): File "[filename.py]", line 66, in main(ciphertext) NameError: name 'ciphertext' is not defined
我的代碼:
def main():
# cipherOne contains encrypted Cesear cipher
myMessage = cipherOne
ciphertext = encryptMessage(key, myMessage)
# Print the encrypted string in ciphertext to the screen, with
# a | (called "pipe" character) after it in case there are spaces at
# the end of the encrypted message.
print(ciphertext)
def encryptMessage(key, message):
# Each string in ciphertext represents a column in the grid.
ciphertext = [''] * key
# Loop through each column in ciphertext.
for col in range(key):
pointer = col
# Keep looping until pointer goes past the length of the message.
while pointer < len(message):
# Place the character at pointer in message at the end of the
# current column in the ciphertext list.
ciphertext[col] += message[pointer]
# move pointer over
pointer += key
# Convert the ciphertext list into a single string value and return it.
return ''.join(ciphertext)
# call main() function.
if __name__ == '__main__':
main()
target = open (filenamenew, 'a')
target.write(ciphertext) #the error
target.close()
我可以將密文中的加密字符串打印到屏幕上,沒有任何問題,但無法解決如何通過此錯誤,我可以將密文附加到.txt文件 .
總結
以上是生活随笔為你收集整理的python将文本文件加密后输出_Python:将Casear密码和柱状转置密码的加密输出写入.txt文件...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: views 多个文件夹 netcore_
- 下一篇: macyy_macyy进频道失败怎么办