1 Attachment(s)
Help Me with an autocipher key in C!!!
Hello,
Can somebody please help me with this code. I've gotten somewhat an idea of what it can be but it is still giving me errors. I also don't understand the algorithm of an autokey cipher so could someone please explain in the program.THANKS!!!
Code:
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>
char key[];
unsigned int easyendecrypt(char c);
int main(void) {
int c;
while ((c = getc(stdin)) !=EOF) {
putc(easyendecrypt(c), stdout);
}
printf("\n");
return 0;
}
unsigned int easyendecrypt(char c) {
char k;
#ifdef DECRYPT
fprintf(stderr, "decrypting with %s\n",key);
k = 'A' + (c - key);
key = k;
return k;
#else
fprintf(stderr,"encrypting with %s\n",key);
k = key + (c + key - 2 * 'A');
key=c;
return k;
#endif
}