#include #include #define MAXLEN 4096 void print_decryption(char* text, int current_key, size_t textlen){ char valid = 0; for(size_t i = 0; i < textlen; i++){ if(islower(text[i])){ text[i] -= 1; if(text[i] < 97) text[i] += 26; } else if(isupper(text[i])){ text[i] -= 1; if(text[i] < 65) text[i] += 26; } if(i > 2) if(!strncmp(text+i-2, "the", 3)) valid = 1; } if(valid) printf("Key %d: %s\n", current_key, text); } int main(int argc, char ** argv){ if(argc < 2){ printf("Usage: %s ", argv[0]); return 1; } FILE *infile = fopen(argv[1], "r"); char data[MAXLEN]; size_t read_size = fread(data, 1, MAXLEN, infile); fclose(infile); for(char i = 1; i < 26; i++) print_decryption(data, i, read_size); return 0; }