Need help with a basic encryption/decryption program
Feb 28, 2014 at 9:42pm UTC
Hello, I'm new to this site and I was wondering if anybody can help me with a basic encryption/decryption assignment for class? Here is the code I have so far.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string method,translation,word,encrypted, defaultmap = "zyxwvutsrqponmlkjihgfedcba" ,usermap;
cout<<"What is the method? (encryption or decryption): " ;
cin>>method;
cout<<"What is the translation map (type 'default' to use default): " ;
cin>>translation;
if (translation=="default" )
{
if (defaultmap.size() != 26)
{
cout<<"Error: Invalid map size." <<endl;
}
else
{
cout<<"What is the single word to translate?: " ;
cin>>word;
}
if (method=="encryption" )
{
int i,wordindex;
for (i=0;i>word.size();i++)
{
wordindex=word.at(i)-'a' ;
word.at(i)=defaultmap.at(wordindex);
cout<<"Encrypted word: " <<word<<endl;
}
}
else if (method=="decryption" )
{
int j,wordindex;
for (j=0;j>word.size();j++)
{
wordindex=word.at(j)-'z' ;
word.at(j)=defaultmap.at(wordindex);
cout<<"Decrypted word: " <<word<<endl;
}
}
}
else
{
cout<<"Error: Invalid method choice." <<endl;
}
}
}
I cannot get to encrypt or decrypt and I'm not sure what changes I should make. Can someone help me in the right direction?
Topic archived. No new replies allowed.