runner% cat caesar2.text i returned, and saw under the sun, that the race is not to the swift, nor the battle to the strong, neither yet bread to the wise, nor yet riches to men of understanding, nor yet favour to men of skill; but time and chance happeneth to them all. runner% cat caesar.c #include #include #include #include char rotate(char c, int key) { int i = 0; char s[] = "abcdefghijklmnopqrstuvwxyz"; if (!islower(c)) return(c); while (i < 26) { if (c == s[i]) return s[(i + key)%26]; i++; } } void main(int argc, char *argv[]) { int encrypt; int key; char c; if (argc != 3) { fprintf(stderr, "Usage: caesar (-d | -e) key\n"); exit(1); } if (strcmp(argv[1], "-e") == 0) encrypt = 1; else if (strcmp(argv[1], "-d") == 0) encrypt = 0; else { fprintf(stderr, "Usage: caesar (-d | -e) key\n"); exit(1); } key = atoi(argv[2]); if (!encrypt) key = (-key + 26)%26; while ((c = getchar()) != EOF) { if (islower(c)) c = rotate(c, key); putchar(c); } } runner% caesar -d Usage: caesar (-d | -e) key runner% caesar -e 3 #include #include #include char rotate(char c, int key); void main(int argc, char *argv[]) { FILE *keyfile; int direction = 1; char c, key_ch; if (argc != 2) { fprintf(stderr, "Usage: beale (-d | -e)\n"); exit(1); } if (strcmp(argv[1], "-e") == 0) direction = 1; else if (strcmp(argv[1], "-d") == 0) direction = -1; else { fprintf(stderr, "Usage: beale (-d | -e)\n"); exit(1); } keyfile = fopen("key.text", "r"); if (keyfile == NULL) { printf("Couldn't open file\n"); exit(1); } while ((c = getchar()) != EOF) { if (islower(c)) { while (!islower(key_ch = fgetc(keyfile))) ; c = rotate(c, ((direction*(key_ch - 'a'))+26)%26); } putchar(c); } } char rotate(char c, int key) { return (c - 'a' + key)%26 + 'a'; } ENCRYPT beale.text, using the simple file of all d characters: runner% beale -e