我已经制作了一个小型加密程序,用于对rot7和rot13键。一切工作正常,除了两个6字母uvwxyz。加密和解密ASCII表的一部分
如果输入ABCDEFGHIJKLMNOPQRSTUVWXYZ,那么加密和解密没问题。但是,如果我输入相同的小写字母,则uvwxyz不起作用。
话虽如此,我已经允许ASCII表内所有可写的字符为有效范围如下:
// allow all writable characters from 32 to 255
if ((str[i] >= 32) && (str[i] <=255))
{
str[i] -= key;
}
这里是加密的过程:
cout << endl;
cout << "Encrypting process started " << endl << endl;
cout << "--------------------------- " << endl;
//get the string length
int i = 0;
int length = str.length();
int key = rot13 ;
int k = 5;
int multiple = 0;
int count = 0;
cout << "the text to encrypt is: " << str << endl;
cout << "text length is: " << length << endl;
cout << "using rot13"<<endl;
cout <<"---------------------------" << endl;
cout << "using rot13" << endl;
//traverse the string
for(i = 0; i < length; i++)
{
count ++;
cout << left;
//if it is a multiple of 5 not the first character change the key
if((multiple = ((i % 5) == 0)) && (count != 1) && (key == rot13)){
key = rot7;
}
//if it is a multiple of 5 not the first character change the key
else if((multiple = ((i % 5) == 0)) && (count != 1) && (key == rot7)) {
key = rot13;
}
// Capital letters are 65 to 90 (a - z)
if ((str[i] >= 32) && (str[i] <= 255))
{
str[i] += key;
}
}
return str;
怎么回事如果我允许这个范围,大写字母可能会起作用,而不是小写字母?它可能是因为别的吗?我已经添加了这些捕获与发生的事情一步一步...希望这有助于
你能告诉我们它不工作? – 2013-04-09 15:25:33
当然,我可以编辑并提供一个捕获 – bluetxxth 2013-04-09 15:27:58
嗯,我的意思只是告诉我们完整的代码和它给你的输出。 – 2013-04-09 15:29:25