I wrote Ceasar cipher and decipher functions and they seam to work fine but for some reason I'm not convinced they will work on my teachers computer what do you guys think?

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;
}
Specificcaly the part that bothers me is

Code:
if(str[i]<='c')
{
	decipher[i-j] = ((str[i] - 2)-'a')+'z';
}
else
{
	decipher[i-j] = str[i] - 3;
}
is this type of manipulation standard and OK?

Last edited by thekevin07; 20Nov2008 at 10:58..