The assignment was to ignore all chars that aren't a-z and crypt them with a key of 3 so a=d, b=e, etc. Then show the crypted txt in blocks of 5 chars
here are the functions
Code:
string decipher(string s)
{
string decipher;
decipher.resize(s.length());
const char *str=s.c_str();
for ( int j=0,i=0; str[i] ; i++ )
{
//make sure string is a char between a-z
//if not, increment j
//j is used so no extra white space is built into decipher if char is not alphabetic
if(str[i]>='a' && str[i]<='z')
{
if(str[i]<='c')
{
decipher[i-j] = ((str[i] - 2)-'a')+'z';
}
else
{
decipher[i-j] = str[i] - 3;
}
}
else
{
j++;
}
}
return decipher;
}
string cipher(string s)
{
string cipher;
cipher.resize(s.length());
const char *str=s.c_str();
for ( int j=0,i = 0 ; str[i] ; i++ )
{
//make sure string is a char between a-z
//if not, increment j
//j is used so no extra white space is built into cipher if char is not alphabetic
if(str[i]>='a' && str[i]<='z')
{
if(str[i]>='x')
{
cipher[i-j] = ((str[i] + 2)-'z')+'a';
}
else
{
cipher[i-j] = str[i] + 3;
}
}
else
{
j++;
}
}
//add spaces every 5 blocks of chars
int g=5;
while(g<=cipher.length())
{
cipher.insert(g," ");
g+=6;
}
return cipher;
}
Code:
if(str[i]<='c')
{
decipher[i-j] = ((str[i] - 2)-'a')+'z';
}
else
{
decipher[i-j] = str[i] - 3;
}

