Task 1 Write a program that allows the user to enter a Strin

Task 1- Write a program that allows the user to enter a String and creates a “Ceasar” Cipher encryption of the input. Change each character by 5. Output the encoded message. Attach Snipping Photo and source code.

Solution

Please follow the code and comments for description :

CODE :

#include <iostream> // required header files
#include <string>

using namespace std;

string encryptMessage(string, int); // function declaration

int main() { // driver method

   string sourceText; // local variables
   int key;
   cout << \"Enter the Text : \"; // prompt for the user
   getline(cin, sourceText); // get the data from the console
   cout << \"Enter the key to Encrypt the message : \"; // prompt for the user
   cin >> key; // get the key
   cout << \"The Encrypted Message is : \" << encryptMessage(sourceText, key) << endl; // print the output
   return 0;
}

string encryptMessage(string sourceText, int key) { // function declaration
   string cryptedMessage = sourceText; // local variables
   for(int current = 0; current < sourceText.length(); current++) // iterate over the loop
   cryptedMessage[current] += key;
   return cryptedMessage; // return the message
}

OUTPUT :

Enter the Text : My name is John Carter
Enter the key to Encrypt the message : 5
The Encrypted Message is : R~%sfrj%nx%Otms%Hfwyjw


Hope this is helpful.

Task 1- Write a program that allows the user to enter a String and creates a “Ceasar” Cipher encryption of the input. Change each character by 5. Output the enc

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site