Question: char* encrypt(string input, int key) { int i = 0; char* res = new char[input.length()]; while (i < input.length()) { if (input[i] >= 'a' &&

char* encrypt(string input, int key) { int i = 0; char* res = new char[input.length()]; while (i < input.length()) { if (input[i] >= 'a' && input[i] <= 'z') res[i] = 'a' + ((input[i] - 'a') + key) % 26; else if (input[i] >= 'A' && input[i] <= 'Z') res[i] = 'A' + ((input[i] - 'A') + key) % 26; i++; } res[i] = '\0'; return res; }
string decrypt(string ciphertext, unsigned char key) { char ch; string result; for(int i = 0; i < ciphertext.size(); ++i) { ch = ciphertext[i]; if(ch >= 'A' && ch <= 'Z') { ch = (char)('A' + ((ch - 'A' - key + 26) % 26)); } else if(ch >= 'a' && ch <= 'z') { ch = (char)('a' + ((ch - 'a' - key + 26) % 26)); } result += ch; } return result; } 

Using these two functions write a c++ program.

The output should be

Enter Input:

Enter Key:

Encrypted Text:

Decrypted text:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!