簡體   English   中英

當我加密多行時,文件寫入僅寫入一行

[英]File write is only writing one line when I have encrypted multiple lines

我正在嘗試加密 1 個文件並將加密文本從第一個文件保存到另一個文件中。 除了它只將 1 行寫入新文件而不是整個文件之外,我已經完成了所有工作。

file1 = open("passwords-plainText", "r")
for line in file1:
    file2 = open("encryptedfile.txt", "w")
    file2.write(encryptVignere(keyGen(), line))

我正在使用的示例文件如下所示

example
secondexample
new line
this is another new line

輸出到我保存的新文件中只寫入第一行而不是其余行,即。)

tyawakud

該文件應該看起來像這樣......

tyawakud
tqiibwaeeonozp
pttzucfqs
foxnzgjwtmbhnpwhjnapmsfg

你應該只打開file2一次:

file1 = open("passwords-plainText", "r")
file2 = open("encryptedfile.txt", "w")

for line in file1:
    file2.write(encryptVignere(keyGen(), line))

否則你只會繼續覆蓋它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM