Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

File encryption is the science of writing the contents of a text file in a secre

ID: 3539291 • Letter: F

Question

File encryption is the science of writing the contents of a text file in a secret code. Your encryption/decryption program should work like a filter, reading the contents of one file, modifying the data into a code, and then writing the coded contents out to a second file. The second file will be a version of the first file, but written in a secret code.

Although there are complex encryption techniques, you should come up with a simple one of your own. For example, you could read the first file one character at a time, and add 10 to the ASCII code of each character before it is written to the second file.

The program should have a menu that allows the user to perform the following tasks:


The source and destination file names should be displayed as part of the menu, if the user has specified.

For example, at the program start the menu could look like:

1: Enter source filename
2: Enter destination filename
3: Encrypt file
4: Decrypt file
0: Exit


After both file names are entered, the menu could look like:

1: Enter source filename
2: Enter destination filename
3: Encrypt file (source.txt)
4: Decrypt file (encrypted.txt)
0: Exit

the using the c++

Explanation / Answer

#include<iostream>

#include<fstream>

#include <stdlib.h>

#include<string.h>



using namespace std;


int main()

{

string source;

string destination;


while(true)

{

cout<<"1: Enter source filename"<<endl

<<"2: Enter destination filename"<<endl

<<"3: Encrypt file"<<endl

<<"4: Decrypt file"<<endl

<<"0: Exit"<<endl;

int menu;

cin>>menu;


if(menu==1)

{

cout<<"1: Enter source filename"<<endl;

cin>>source;

}

else if(menu==2)

{

cout<<"2: Enter destination filename"<<endl;

cin>>destination;

}

else if(menu==3)

{

if((source.empty())||(destination.empty()))

{

cout<<"You havenot entered source file"<<endl;

}

else

{

ifstream file1;

file1.open(source.c_str());


ofstream file2;

file2.open(destination.c_str());

char c;

while(!file1.eof())

{

file1>>c;

char newc= int(c)+12;

file2<<newc<<" ";

}

file1.close();

file2.close();

}

}

else if (menu==4)

{

if((destination.empty())||(source.empty()))

{

cout<<"You have not entered destination file"<<endl;

}

else

{

ofstream file1;

file1.open(source.c_str());

ifstream file2;

file2.open(destination.c_str());


char c;

while(!file2.eof())

{

file2>>c;

char newc=int(c)-12;

file1<<newc;

}

file1.close();

file2.close();

}

}

else if(menu==0)

{

exit (EXIT_SUCCESS);

}

}

}








Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote