密码溢出

前端之家收集整理的这篇文章主要介绍了密码溢出前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在加密如下,但不知道如果它们移出范围,如何阻止大写字母进入其他符号,同样小写字母超出小写字母的范围.如何让它们围成一圈并停止溢出?谢谢
int size = strlen(plain_text);
int arrayelement = 0;
for(arrayelement = 0; arrayelement < size; arrayelement++)
{
    if (islower(plain_text[arrayelement]))
    {
        ciphered_text[arrayelement] = (int)(plain_text[arrayelement] + shiftkey);
    }
    else if (isupper(plain_text[arrayelement]))
    {
        ciphered_text[arrayelement] = (int)(plain_text[arrayelement] + shiftkey);
    }
}

ciphered_text[size] = '\0';
printf("%s",ciphered_text);

解决方法

我猜你使用像char这样的类型,这样就可以轻松解决不溢出问题
int tmp_ciphered = (my_char + shift) % 0xff;
char ciphered = (char)(tmp_ciphered);

然后你转身不要溢出,这是一个戒指

猜你在找的C&C++相关文章