Question: The following program in C + + is able to encrypt a file using the Vigen re cypher, and writes the file to encrypted.txt file,
The following program in C is able to encrypt a file using the Vigenre cypher, and writes the file to encrypted.txt file, but it is not able to decrypt the file again. Please modify the program so that it can decrypt the file back to the original as well as encrypt. This is due by tomorrow. Thanks!
Code:
#include
#include
#include
#include
using namespace std;
char encryptCharchar ch char key
if isalphach
bool isUpper isupperch;
char base isUpper A : a;
return base ch key base;
else
return ch;
char decryptCharchar ch char key
if isalphach
bool isUpper isupperch;
char base isUpper A : a;
return base ch key base;
else
return ch;
void processFilestring filename, string key, bool encrypt
ifstream inFilefilename;
ofstream outFileencrypt "encrypted.txt : "decrypted.txt;
if inFile.isopenoutFile.isopen
cerr "Error opening file." endl;
return;
char ch;
int keyIndex ;
while inFilegetch
char encryptedChar encrypt encryptCharch keykeyIndex : decryptCharch keykeyIndex;
outFile encryptedChar;
cout encryptedChar;
keyIndex keyIndex key.length;
inFile.close;
outFile.close;
int main
string choice, key, filename;
while true
cout "Encrypt or decrypt edq to quit: ;
cin choice;
if choice e
cout "Enter key: ;
cin key;
cout "Enter plaintext filename: ;
cin filename;
processFilefilename key, true;
else if choice d
cout "Enter key: ;
cin key;
cout "Enter encrypted filename: ;
cin filename;
processFilefilename key, false;
else if choice q
break;
else
cout "Invalid choice." endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
