How can you tell an extrovert from an introvert at NSA? Va gur ryringbef, gur rkgebireg ybbxf ng gur BGURE thl’f fubrf.
I found this joke on USENET, but the punchline is scrambled. Maybe you can decipher it? According to Wikipedia, ROT13 (http://en.wikipedia.org/wiki/ROT13) is frequently used to obfuscate jokes on USENET.
Hint: For this task you’re only supposed to substitute characters. Not spaces, punctuation, numbers etc.
Test examples:
"EBG13 rknzcyr." -->
"ROT13 example."
"This is my first ROT13 excercise!" -->
"Guvf vf zl svefg EBG13 rkprepvfr!"
Solution:
#include <string.h>
char *rot13(char *str_out, const char *str_in)
{
// write to str_out and return it
*str_out = '\0';
char b;
unsigned long i;
for (i = 0; i < strlen(str_in); i++)
{
b = str_in[i];
if ((b >= 'A' && b <= 'M') || (b >= 'a' && b <= 'm'))
b += 13;
else if ((b >= 'N' && b <= 'Z') || (b >= 'n' && b <= 'z'))
b -= 13;
strncat(str_out, &b, 1);
}
return str_out;
}