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 file in a secret cod

ID: 3548581 • Letter: F

Question

File encryption is the science of writing the contents of a file in a secret code. Your encryption program should work like a filter, reading the contents of one file, modifying the information 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.



Explanation / Answer

void Encryption()
{
cout << " What is the location of the file you would like to encrypt?";
string fileloc;
getline (cin, fileloc); //cin gets the file location as a string
cin >> fileloc;
infile.open (fileloc.c_str()); //opens the file to be encrypted

cout << " What is the password you would like to use to create the encryption?";
cout << " Please enter a four letter word.";
string password;
getline (cin,password); //cin gets the meshing password as a string
cin >> password;

cout << " What is the name of the file to which you would like to print the encryption?";
string outfileloc;
getline (cin, outfileloc); //cin gets the output file as a string
cin >> outfileloc;
outfile.open (outfileloc.c_str()); //opens the output file

while (!infile.eof()) //while not the end of the file
{
for (int i=0 ;i<4 ; i++) //for loop cycles through the positions of the password array until end of file is reached
{
char name; //character from file to be encrypted
infile.get(name); //gets character from the file
name = name + password[i]; //adds the part of the password array
name = name - password[0]; //subtracts the first letter of the password (keeps characters printable)
outfile << name; //prints that character to the output file
}
}

infile.close(); //closes the original file
outfile.close(); //closes the file encryption

cout << " "; //aesthetic purposes
}


void Decryption()
{
cout << " What is the location of the file you would like to decrypt?";

string fileloc;
getline (cin, fileloc); //cin gets the location of the file to be decrypted as a string
cin >> fileloc;
infile2.open (fileloc.c_str()); //opens the file using infile2 (different input file)

cout << " What is the password used when the text was encrypted?";
cout << " Please enter the four letter word.";
string password;
getline (cin,password); //gets password used for encrypting as a string
cin >> password;
cout << " ";

while (!infile2.eof()) //while not the end of the file
{
for (int i=0 ;i<4 ; i++) //for loop cycles through the positions of the password array until end of file is reached
{
char name; //character from file to be decrypted
infile2.get(name); //gets character from file

name = name + password[0]; //re-adds the first letter of the password
name = name - password[i]; //subtracts the proper letter from the password array
cout << name; //prints decrypted character to screen
}

}

infile2.close(); //closes file that was being decrypted

cout << " "; //aesthetic purposes
}

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