Question: I'm needing help with the following c++ code: Create a program that decodes and encodes plain text using a simple Caesar cipher. Text is encoded
I'm needing help with the following c++ code:
Create a program that decodes and encodes plain text using a simple Caesar cipher. Text is encoded using a Caesar cipher by simple substitution wherein the letters in the message are replaced with some letter of a fixed number down the alphabet. You will use the
The main function should have a menu with two options: decode or encode. Those options should call separate functions decode and encode. Encode function receives a string that is normal text and returns an encoded string. The Decode function should receive the coded string and return 25 different lines, each with a possible solution to the message. Those lines are created by showing each possibility, shifting the letters down the alphabet by one each time.
Here is what I have completed:
#include
#include
#include
#include
/*
Name: John Hawkins
Date: 3/24/2018
File Name: HawkinsJ Caesar Cypher
Description: This program allows the user to encrypt and decrypt messages using teh Caesar Cypher.
*/
using namespace std;
void encode();
//encodes a string message from teh user and outputs the encoded message
void decode();
//prompts the user for an encoded message and displays all possible (25)
//decoded plain text
int main(int argc, char** argv)
{
string strChoice;
do
{
cout<< "++++++++++Caesar Cypher++++++++++++ "
<< "1. \tEncode "
<< "2. \tDecode "
<< "select a menu option: ";
//read user choice
getline(cin,strChoice);
if(strChoice == "1")
{
encode();
}
else if(strChoice == "2")
{
//decode();
}
else
{
cout<< "Invalid choice. choose 1 or 2";
}
}while(strChoice != "1" || strChoice != "2");
return 0;
}
void encode()
{
//variables
string strMessage;
srand(time(0));
int randNum = rand()%25+1;
char c;
//prompt user for the message
cout<< "Type a message to enode: ";
getline(cin,strMessage);
for(int n=0; n< strMessage.length(); n++)
{
//weed out spaces
if(isalpha(strMessage.at(n)))
{
c = toupper(strMessage.at(n));
c = (((c-65)+randNum)%26)+65;
}
else
{
c = strMessage.at(n);
}
cout<< c;
}
cout<< endl << endl;
}//end encode
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
