I am trying to encrypt 1 file and save the encrypted text from the first file into another file. I have it all working besides that it is only writing 1 line into the new file instead of the entire file.
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:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.