这是我的ROT13密码的代码。 它适用于大写,但当我输入你好作为输入时,它会返回[X__b可以有人帮助我在这里......
void encrypt(char *cipher,int key)
{
int i = 0;
while(cipher[i] != '\n')
{
if(isalpha(cipher[i]))
{
if((cipher[i] + key) > 'Z' || (cipher[i] + key) > 'z')
{
cipher[i] = cipher[i] + key - 26;
}
else if((cipher[i] + key) >= 'a' && (cipher[i] + key) <= 'z')
{
cipher[i] = cipher[i] + key;
}
else if((cipher[i] + key) >= 'A' && (cipher[i] + key) <= 'Z')
{
cipher[i] = cipher[i] + key;
}
}
i++;
}
}
答案 0 :(得分:2)
这个条件
f((cipher[i] + key) > 'Z' || (cipher[i] + key) > 'z')
对于所有小写字母都是true,第二部分(cipher[i] + key) > 'z'
是多余的