Created
July 19, 2017 01:15
-
-
Save sheeit/e0f134afb2fce48d79937ccd5c3a4b10 to your computer and use it in GitHub Desktop.
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 <ctype.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
char rot13_letter(char letter); | |
int main(int argc, char **argv) | |
{ | |
int i; | |
char *c; | |
for (i = 1; i < argc; ++i) { | |
c = argv[i]; | |
while (*c) | |
fputc(rot13_letter(*(c++)), stdout); | |
fputc(i == argc - 1 ? '\n' : ' ', stdout); | |
} | |
exit(EXIT_SUCCESS); | |
} | |
char rot13_letter(char letter) | |
{ | |
short int cmp_letter = 13; | |
short int rot13_offset; | |
char rot13 = letter; | |
if (!isalpha(letter)) | |
return letter; | |
cmp_letter += isupper(letter) ? 'A' : 'a'; | |
rot13_offset = letter < cmp_letter ? 1 : -1; | |
rot13 += (char) (13 * (int) rot13_offset); | |
if (!isalpha(rot13) || isupper(letter) != isupper(rot13)) | |
return '?'; | |
return rot13; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment