/****************************************************************************/ /** **/ /** Vig.c --- performs vignere encryption on standard input. **/ /** **/ /** To compile: gcc -ansi -o vignere vig.c **/ /** To run: vig keyword < input.txt **/ /** **/ /** "vig -d keyword" performs decryption. **/ /** "vig -t keyword" strips away all non-letters. **/ /** **/ /****************************************************************************/ #include #include #define INDEX(c) ( ((c)|' ')-'a' ) #define BASE(c) ( ((c)&' ')?'a':'A' ) char *password; int keysize; int onlytext=0, decrypt=0; int everything_is_cool( int argc, char ** argv ); int main( int argc, char ** argv ) { int count=0; unsigned char ch, key; if( everything_is_cool( argc, argv ) ) { ch = getchar(); /* get first character */ while( !feof(stdin) ) { if( isalpha(ch) ) { key = INDEX( password[count] )+1; if( decrypt ) key = 26-key; ch = BASE(ch) + (INDEX(ch)+key)%26; putchar(ch); count++; if(count==keysize) count=0; } else if( !onlytext ) putchar(ch); ch = getchar(); /* get next character */ } } return 0; } int everything_is_cool( int argc, char ** argv ) { int i, j, coolness=0; for( i=1, password=NULL; i