日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

python将文本文件加密后输出_Python:将Casear密码和柱状转置密码的加密输出写入.txt文件...

發(fā)布時(shí)間:2024/7/23 python 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python将文本文件加密后输出_Python:将Casear密码和柱状转置密码的加密输出写入.txt文件... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我希望這很容易解決 . 我使用Python在Windows Powershell中獲得的錯(cuò)誤如下:

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()

我可以將密文中的加密字符串打印到屏幕上,沒有任何問題,但無法解決如何通過此錯(cuò)誤,我可以將密文附加到.txt文件 .

總結(jié)

以上是生活随笔為你收集整理的python将文本文件加密后输出_Python:将Casear密码和柱状转置密码的加密输出写入.txt文件...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。