I was wondering how in a Caesar cipher one would detect the amount of shifts in a encrypted text file that is read from the program and then display that certain amount? Thank you! EDIT** I also read in a smallDictionary file for argv[2]. The rotate function:
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);
}