Please dont use pointers or other very high level stuff. I think ASCII codes cou
ID: 3625423 • Letter: P
Question
Please dont use pointers or other very high level stuff. I think ASCII codes could dothe trick for this problem, but im not sure...
Caesar Cypher Algorithm
Example:
Let, shift parameter = 3
Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cypher: DEFGHIJKLMNOPQRSTUVWXYZABC
Plain Text: “Solve to unveil the mysteries of the elders”
Cypher-text: “vroyh wr xqyho wkh pbvwhulhv ri wkh hoghuv”
REQUIREMENTS ARE : To design a menu to select encryption or decryption.User input string is always 36 characters.User defined shift parameter for Caesar cypher.Encrypted or decrypted output (i.e. either plaintext or cyphertext) as per user’s choice
Explanation / Answer
please rate - thanks
hope this is good
#include <iostream>
#include <string>
using namespace std;
int main()
{
int choice,shift,i,j;
string input;
char c;
do
{
do{
cout<<"What would you like to do: ";
cout<<"1. Encrypt code ";
cout<<"2. Decrypt code ";
cout<<"3. exit ";
cin>>choice;
if(choice<1||choice>3)
cout<<"Invalid choice ";
}while(choice<1||choice>3);
if(choice!=3) //don't do if exiting
{cout<<"Enter shift amount: ";
cin>>shift;
cin.ignore( 10,' '); //get rid of enter from the input buffer
cout<<"Enter text: ";
getline(cin,input);
if(choice==1) //encrypt
{for(i=0;i<=input.length();i++) //for every character input
{c=input[i];
if(c>='a'&&c<='z'||c>='A'&&c<='Z') //only code letters
{c+=shift; //add shift , but if > z must "wrap around"
if(c>'z'||c>'Z'&&c<'a') //ascii A=65, Z=90,a=97,z=122
c-=26;
}
cout<<c;
}
}
else //decrypt
{for(i=0;i<=input.length();i++) //for every character input
{c=input[i];
if(c>='a'&&c<='z'||c>='A'&&c<='Z') //only code letters
{c-=shift; //add shift , but if > z must "wrap around"
if(c<'A'&&c<'Z'||c<'a') //ascii A=65, Z=90,a=97,z=122
c+=26;
}
cout<<c;
}
}
}
cout<<endl;
}while(choice!=3);
system("pause");
return 0;
}