[英]File write is only writing one line when I have encrypted multiple lines
I am trying to encrypt 1 file and save the encrypted text from the first file into another file.我正在尝试加密 1 个文件并将加密文本从第一个文件保存到另一个文件中。 I have it all working besides that it is only writing 1 line into the new file instead of the entire file.除了它只将 1 行写入新文件而不是整个文件之外,我已经完成了所有工作。
file1 = open("passwords-plainText", "r")
for line in file1:
file2 = open("encryptedfile.txt", "w")
file2.write(encryptVignere(keyGen(), line))
The example file I am using looks like this我正在使用的示例文件如下所示
example
secondexample
new line
this is another new line
The output into the new file I am saving to only writes the first line and not the rest of the lines ie.)输出到我保存的新文件中只写入第一行而不是其余行,即。)
tyawakud
The file should look like this instead...该文件应该看起来像这样......
tyawakud
tqiibwaeeonozp
pttzucfqs
foxnzgjwtmbhnpwhjnapmsfg
You should only open file2
once:你应该只打开file2
一次:
file1 = open("passwords-plainText", "r")
file2 = open("encryptedfile.txt", "w")
for line in file1:
file2.write(encryptVignere(keyGen(), line))
Otherwise you just keep overwriting it.否则你只会继续覆盖它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.