December 8, 2023
ROT13

Belajar Bahasa C – ROT13

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;
}

Rajo Intan

Blogger, pemiliki Onestring Lab, menulis artikel terkait teknologi informasi dan pendidikan. Web Developer, berpengalaman lebih dari 20 tahun mengembangkan berbagai aplikasi dan sistem informasi. Kerjasama kontak di onestringlab@gmail.com atau https://forms.gle/xAGKkpi6B3BzJyzk7

View all posts by Rajo Intan →

Leave a Reply

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.