Last active
November 24, 2018 19:22
-
-
Save Sam-Belliveau/f3ffb57673f09d4709db7c5bcb509626 to your computer and use it in GitHub Desktop.
Here is a really simple example for ROT13 cipher. Used for demonstation purposes only. Made to be as readable as possible.
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> /* putchar, printf */ | |
| void printRot13(const char* str) | |
| { | |
| /* loop through string. Strings end with a \0 */ | |
| for(; *str != '\0'; ++str) | |
| { | |
| /* If letter is in the lower 13 letters, add 13 */ | |
| if (*str >= 'A' && *str <= 'M') { putchar(*str + 13); } | |
| else if (*str >= 'a' && *str <= 'm') { putchar(*str + 13); } | |
| /* If letter is in the upper 13 letters, sum 13 */ | |
| else if (*str >= 'N' && *str <= 'Z') { putchar(*str - 13); } | |
| else if (*str >= 'n' && *str <= 'z') { putchar(*str - 13); } | |
| /* If the letter can not be encrypted * | |
| * print the original letter */ | |
| else { putchar(*str); } | |
| } | |
| /* Add a space between words */ | |
| putchar(' '); | |
| } | |
| int main(int argc, char** argv) | |
| { | |
| /* Check to see if there is any input text */ | |
| if(argc == 1) | |
| { | |
| /* Print error if there is none */ | |
| printf("%s: No Input Text!\n", argv[0]); | |
| } | |
| else | |
| { | |
| /* Loop through all the inputs * | |
| * and encrypt them all */ | |
| for(int i = 1; i < argc; ++i) | |
| { printRot13(argv[i]); } | |
| /* Print new line, for the shell */ | |
| putchar('\n'); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment