#include #include int caesar(int key, char ch) { return (ch + key) % 256; } int encrypt_file(int key, FILE* file) { int ch = 0; while ( (ch = fgetc(file)) != EOF ) fputc( caesar(key, ch), stdout); return 0; } int main(int argc, char* argv[]) { if ( argc <= 1 ) { printf("Usage: caesar [FILES]\n"); return 0; } int key = atoi(argv[1]); if ( argc == 2 ) return encrypt_file(key, stdin); for (int i = 2; i < argc; ++i ) { FILE* file = fopen(argv[i], "r"); if ( ! file ) return fprintf(stderr, "caesar: could not open %s\n", argv[i]); encrypt_file(key, file); fclose(file); } }