Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started