/* Rot-13 encoder/decoder in C
*
* This wretched little monstrosity is in the public domain.
* A much better solution is to use sed or tr. If you're on
* Windows, go to the GNUish Project and download sed.
*
* As with any simple character translation thing, a
* lookup table would be more efficient, but... come on!
*
* wharfinger 11/5/00
*/
#include <stdio.h>
#include <ctype.h>
int r13( int c );
int main()
{
int c;
while ( ( c = getchar() ) != EOF )
putchar( r13( c ) );
return 0;
}
int r13( int c )
{
/* Okay, it's a nested ternary. I know.
This should probably be a macro, but macros this complex
get on my nerves.
'm' is the thirteenth letter of the alphabet.
I mean, like, in case you didn't know or something.
*/
return ( isalpha( c ) )
? ( ( tolower( c ) > 'm' ) ? ( c - 13 ) : ( c + 13 ) )
: c;
}