Hello
I wrote the below program to turn encrypt, it turns "a to z" "b to y" "c to x" etc.
but the problem is, it is only working on some letters about half and it looks like only the last half of the alphabet.
any suggestions?
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <string>
usingnamespace std;
int main ()
{
string method, map, word, str;
int encryption, decryption;
cout<<"What is the method (encryption or decryption)?"<<endl;
cin>>method;
if (method=="encryption")
{
cout<<"What is the translation map (type 'default' to use default):"<<endl;
cin>>map;
if (map=="default")
{
cout<<"What is the single word to translate:"<<endl;
cin>>word;
string str=word;
for (unsigned i=0; i<str.length(); i++)
{
if (str.at(i)=='a')
str.at(i)='z';
if (str.at(i)=='b')
str.at(i)='y';
if (str.at(i)=='c')
str.at(i)='x';
if (str.at(i)=='d')
str.at(i)='w';
if (str.at(i)=='e')
str.at(i)='v';
if (str.at(i)=='f')
str.at(i)='u';
if (str.at(i)=='g')
str.at(i)='t';
if (str.at(i)=='h')
str.at(i)='s';
if (str.at(i)=='i')
str.at(i)='r';
if (str.at(i)=='j')
str.at(i)='q';
if (str.at(i)=='k')
str.at(i)='p';
if (str.at(i)=='l')
str.at(i)='o';
if (str.at(i)=='m')
str.at(i)='n';
if (str.at(i)=='n')
str.at(i)='m';
if (str.at(i)=='o')
str.at(i)='l';
if (str.at(i)=='p')
str.at(i)='k';
if (str.at(i)=='q')
str.at(i)='j';
if (str.at(i)=='r')
str.at(i)='i';
if (str.at(i)=='s')
str.at(i)='h';
if (str.at(i)=='t')
str.at(i)='g';
if (str.at(i)=='u')
str.at(i)='f';
if (str.at(i)=='v')
str.at(i)='e';
if (str.at(i)=='w')
str.at(i)='d';
if (str.at(i)=='x')
str.at(i)='c';
if (str.at(i)=='y')
str.at(i)='b';
if (str.at(i)=='z')
str.at(i)='a';
}
cout<<str<<endl;
}
}
elseif (method=="decryption")
{
cout<<"you entered decryption"<<endl;
}
else
{
cout<<"not valid input"<<endl;
}
return 0;
}
#include <iostream>
#include <cstdlib>
#include <string>
usingnamespace std;
int main ()
{
string method, map, word, str;
int encryption, decryption;
cout<<"What is the method (encryption or decryption)?"<<endl;
cin>>method;
if (method=="encryption")
{
cout<<"What is the translation map (type 'default' to use default):"<<endl;
cin>>map;
if (map=="default")
{
cout<<"What is the single word to translate:"<<endl;
cin>>word;
for(int i = 0; i < word.length(); i++)
word.at(i) = 'a' - word.at(i) + 122; //'z' == 122
cout<<word<<endl;
}
}
elseif (method=="decryption")
cout<<"you entered decryption"<<endl;
else
cout<<"not valid input"<<endl;
system("pause");
return 0;
}