这是我的ROT13密码代码。它适用于大写字母,但是当我输入 hello 时,它会返回 [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++;
}
}
此条件
f((cipher[i] + key) > 'Z' || (cipher[i] + key) > 'z')
对于所有小写字母都是正确的,第二部分(cipher[i] + key) > 'z'
多余的