/* Program rotx ("Rotate X") performs a Caeser Cipher on text read from standard input, and writes the ciphertext to standard output. Program encrypts one character at a time. John Nordlie, 1995 */ #include #include int main(int argc, char *argv[]) { int character, rotation; /* check for proper number of arguments, exit if not */ if (argc != 2) { printf("Usage: rotx < \n"); printf("or: | rotx \n"); exit(1); } /* first argument is offset */ rotation = atoi(argv[1]); /* get the first character */ character = fgetc(stdin); /* main loop */ while (!feof(stdin)) { /* if character in A - Z, rotate it */ if ((character < 91)&&(character > 64)) { character = character + rotation; if (character > 90) { character = character - 26; } } else { /* if character in a - z, rotate it */ if ((character < 123) && (character > 96)) { character = character + rotation; if (character > 122) { character = character - 26; } } } /* send possibly modified character to output */ printf("%c", character); /* get the next input character */ character = fgetc(stdin); } /* end if */ } /* end main */