我想知道如何在凯撒密码中检测从程序中读取的加密文本文件中的移位量,然后显示该特定量?谢谢!编辑** 我还阅读了一个用于 argv[2] 的 smallDictionary 文件。旋转功能:
int rotate(int c, int n){
if (n == 0) return c;
int nRot = abs(n) % (RANGECHAR + 1);
if(n > 0)
return rotatePlus(c + nRot);
else
return rotateMinus(c - nRot);
}
int main( int argc, char *argv[]){
FILE *fp = stdin; // defaults
int n = 13;
int shift;
int i = 0;
// process command line
switch(argc) {
case 2: // only have n, assumed input from stdin
n = atoi(argv[1]);
break;
case 3: // have n and input file
fp = fopen(argv[1], "r"); // should check for problems
n = atoi(argv[2]);
break;
default:
fp = stdin;
n = 13;
}
// rotate text
int c;
while( (c = fgetc(fp)) != EOF){
if(!isspace(c)){
c= rotate(c,n);
}
i++;
printf("%c", c);
}
fclose(fp);
}