Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need this in c++// Please explain your code (Change up the code please) #include #include using namespace std; // get the ciphered text string encryption(string

Need this in c++// Please explain your code

image text in transcribed

(Change up the code please)

#include

#include

using namespace std;

// get the ciphered text

string encryption(string strng, int);

// decrypt the cipher text

string decryption(string strng, int);

int main()

{

cout

int n;

cin>>n;

cout

string strng;

//gets input

cin>>strng;

// get the ciphered text

string cipher = encryption(strng, n);

// decrypt the cipher text

string plaintext = decryption(cipher, -n);

cout

return 0;

}

// get the ciphered text

string encryption(string strng, int n)

{

int i;

for( i = 0 ; i

{

// get the ascii code convert string to int

int ascii = (int)strng[i];

ascii = ascii + n;

if(ascii

ascii = 91 - ( 65 - ascii );

else if(ascii > 90)

ascii = 64 + (ascii - 90);

// update the character with the ciphered text

strng[i] = (char)ascii;

}

return strng;

}

// decrypt the cipher text

string decryption(string strng, int n)

{

int i;

for( i = 0 ; i

{

// get the ascii code

//changes the ascii into the string

int ascii = (int)strng[i];

ascii = ascii + n;

if(ascii

ascii = 91 - ( 65 - ascii );

else if(ascii > 90)

ascii = 64 + (ascii - 90);

// update the character with the ciphered text

strng[i] = (char)ascii;

}

return strng;

}

You are now to extend the above program to take as inputs files. The program should be able to read a file and encode or decode it as needed For the sake of simplicity, we assume that you only need to change letters [A-Z] in the file. You can safely ignore other letters in the file (i.e., keep those as is.) Encrypting a file to cyphertext Encrypt a file in. txt containing plaintext to a file out.txt containing ciphertext using shift . Flag -e here refers to encryption. $ cf -e in.txt out.txt Example Consider f1.txt HELLO WORLD THIS IS AMAZING WHY IS THIS SO AMAZING I HAVE NO IDEA 11231 After running the following command $ ./cf -e 3 fl.txt f2.txt File f2.txt looks like KHOOR ZRUOG WKLV LV DPDCLQJ ZKB LV WKLV VR DPDCLQJ L KDYH QR LGHD 11231 Decrypting a file to plaintext Decrypting a file in.txt containing ciphertext to a file out.txt containing plaintext using shift (shift). Flag -d here refers to decryption. $ cf -d in.txt out.txt Example After running the following command $ ./cf -d 3 f2.txt f3.txt File f3.txt looks like HELLO WORLD THIS IS AMAZING WHY IS THIS SO AMAZING I HAVE NO IDEA 11231 You are now to extend the above program to take as inputs files. The program should be able to read a file and encode or decode it as needed For the sake of simplicity, we assume that you only need to change letters [A-Z] in the file. You can safely ignore other letters in the file (i.e., keep those as is.) Encrypting a file to cyphertext Encrypt a file in. txt containing plaintext to a file out.txt containing ciphertext using shift . Flag -e here refers to encryption. $ cf -e in.txt out.txt Example Consider f1.txt HELLO WORLD THIS IS AMAZING WHY IS THIS SO AMAZING I HAVE NO IDEA 11231 After running the following command $ ./cf -e 3 fl.txt f2.txt File f2.txt looks like KHOOR ZRUOG WKLV LV DPDCLQJ ZKB LV WKLV VR DPDCLQJ L KDYH QR LGHD 11231 Decrypting a file to plaintext Decrypting a file in.txt containing ciphertext to a file out.txt containing plaintext using shift (shift). Flag -d here refers to decryption. $ cf -d in.txt out.txt Example After running the following command $ ./cf -d 3 f2.txt f3.txt File f3.txt looks like HELLO WORLD THIS IS AMAZING WHY IS THIS SO AMAZING I HAVE NO IDEA 11231

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is the relationship between humans?

Answered: 1 week ago