Created
February 21, 2015 13:23
-
-
Save v3l0c1r4pt0r/5e4a47c8822ecbd93760 to your computer and use it in GitHub Desktop.
ROT13 encoder/decoder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char **argv) { | |
int ch = '\0'; | |
while((ch = fgetc(stdin)) != EOF) | |
{ | |
/* for every char in stdin */ | |
unsigned char c = (unsigned char)ch; | |
if( | |
(c >= 'a' && c <= 'z') || | |
(c >= 'A' && c <= 'Z') | |
) | |
{ | |
/* if letter */ | |
unsigned char abs; | |
if(c >= 'a' && c <= 'z') /* for every small letter */ | |
abs = c - 'a'; | |
else if(c >= 'A' && c <= 'Z') /* for every big letter */ | |
abs = c - 'A'; | |
abs = abs + 13; /* dot rot13 */ | |
if(abs >= 26) | |
abs -= 26; /* wrap */ | |
if(c >= 'a' && c <= 'z') /* for every small letter */ | |
c = abs + 'a'; | |
else if(c >= 'A' && c <= 'Z') /* for every big letter */ | |
c = abs + 'A'; | |
}; | |
printf("%c",c); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment