//------------------------------------------------------------------- // encrypt.cpp // // This program can act as a pipe to perform simple encryption. // // Usage example: $ cat message.txt | encrypt // // programmer: ALLAN CRUSE // written on: 14 DEC 2004 //------------------------------------------------------------------- #include // for read(), write() int main( int argc, char **argv ) { // initialize the cipher array (with ascii codes) char cipher[ 256 ]; for (int i = 0; i < 256; i++) cipher[ i ] = i; // scramble the translations for uppercase letters for (int i = 0; i < 26; i++) cipher[ 'A' + i ] = 'A' + ( i + 17 )%26; // scramble the translations for lowercase letters for (int i = 0; i < 26; i++) cipher[ 'a' + i ] = 'a' + ( i + 23 )%26; // scramble the translations for decimal numerals for (int i = 0; i < 10; i++) cipher[ '0' + i ] = '0' + ( i + 4 )%10; // output the translation for each character read char ch; while ( read( 0, &ch, 1 ) == 1 ) write( 1, &cipher[ ch ], 1 ); }