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

Encryption and Decryption are two cryptographic techniques. Encryption is used t

ID: 3531720 • Letter: E

Question

Encryption and Decryption are two cryptographic techniques. Encryption is used to transform text to meaningless characters, and decryption is used to transform meaningless characters into meaningful text. The algorithm that does the encryption is called a cipher. A simple encryption algorithm is Caesar cipher, which works as follows: replace each clear text letter by a letter chosen to be n places later in the alphabet. The number of places, n, is called the cipher key. For example, if the cipher key is 3, the clear text

Explanation / Answer

#include<iostream>


#include<fstream>


using namespace std;

void encrypt(char* inputFile,char* outputFile)

{

ofstream out(outputFile);

ifstream in(inputFile);

char ch;

if(!out)

{

cout << "Cannot open output file. ";

return;

}

if(!in)

{

cout << "Cannot open input file. ";

return;

}


while(in)

{

in.get(ch);

if(in)

{

if(((ch>='A')&&(ch<='Z'))||((ch>='A')&&(ch<='Z')))

ch=(ch-'A'+5)&+'A';

out<<ch;

}

}



}

void decrypt(char* inputFile,char* outputFile)

{

ofstream out(outputFile);

ifstream in(inputFile);

char ch;

if(!out)

{

cout << "Cannot open output file. ";

return;

}

if(!in)

{

cout << "Cannot open input file. ";

return;

}


while(in)

{

in.get(ch);

if(in)

{

if(((ch>='A')&&(ch<='Z'))||((ch>='A')&&(ch<='Z')))

ch='Z'-('Z'-ch+5)&

out<< ch;

}


}

}

int main()

{

int choice;

char option;

char inputFile[20];

char outputFile[20];

cout<<"Welcome to ENGR1200U Cryptographic Technique program ";

do

{

cout<<"please enter your selection ";

cout<<"1.Encrypt ";

cout<<"2. Decrypt ";

cin>>choice;

if(choice==1)

{

cout<<"Enter input File ";

cin>>inputFile;

cout<<"Enter output File ";

cin>>outputFile;

encrypt(inputFile,outputFile);

cout<<"encrypted successfully ";


}


else if(choice==2)

{

cout<<"Enter input File ";

cin>>inputFile;

cout<<"Enter output File ";

cin>>outputFile;

decrypt(inputFile,outputFile);

cout<<"decrypted successfully ";


}


cout<<" enter your selection ";

cout<<" C . continue ";

cout<<" E. exit ";

cin>>option;

}while(option!='E');


return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote