I’m facing unexpected problem in my Caesar’c cipher. Caesar is when you encrypt text by shifting every letter by n numbers. So if it is 1, abc will be bcd. I work on the program that does that in C, but it works strange for some characters, regular letters, although it should be correct. Here is the problem syntax:
for (int i = 0; i < strlen(text); i++)
{
if (text[i] != ' ')
{
// printf("\n%i\n", key);
text[i] = text[i] + key;
if (text[i] > 122)
{
text[i] = text[i] + 97 - 122;
}
}
}
I wrap around by doing that math in the end.
Can you please help me whats wrong with it?
EDIT: This code is fine, problem is with handling of command line parameters.
Use
96in place of97problem solvedso when you wrap around then actually increase by 1 extra value
think of this;
Try using ‘a’ , ‘b’ , .. .. .. ,’z’ like this rather their actual values
using
' 'single quote inside char gives you integral value i.e. ASCII valuehere is the code :