I have a kind of working caesarprogram but if the key is to high it prints out weird stuff. For example: key: 2 xyz prints out: zab but key: 28 xyz prints out: JKL and key: 44 prints out JKL as well. I'm already looking at the code for some time, but can still not figure out what is the problem.
Is there someone who sees the problem and can give me a hint? Thanks a lot.
Here is the piece of code where it's going wrong.
for (int i = 0, n = strlen(s)+1; i < n; i++)
{
if isalpha(s[i])
{
char new = (s[i]+k);
if isupper (s[i])
{
if (new <= 90 && new >= 65)
{
printf("%c", new);
}
else
{
printf("%c", ((new-65)%26)+65);
}
}
else if islower (s[i])
{
if (new <= 122 && new >= 97)
{
printf("%c", new);
}
else
{
printf("%c", ((new-97)%26)+97);
}
}
}
k
? Key?