A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Rot13 in C page! Here, you’ll find the source code for this program as well as a description of how the program works.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void rot13(char *str) {
for(int i = 0; str[i] != '\0'; i++) {
char c = *(str + i);
if(('a' <= c && 'n' > c) || ('A' <= c && 'N' > c)) {
*(str + i) += 13;
} else if(('n' <= c && 'z' >= c) || ('N' <= c && 'Z' >= c)) {
*(str + i) -= 13;
}
}
}
int main(int argc, char *argv[]) {
if(argc == 2 && strlen(argv[1]) != 0 && !isdigit(*argv[1])) {
rot13(argv[1]);
printf("%s\n", argv[1]);
} else {
printf("Usage: please provide a string to encrypt\n");
}
return 0;
}
If you see anything you’d like to change or update, please consider contributing.
Note: The solution shown above is the current solution in the Sample Programs repository as of Oct 09 2019 20:06:02. The solution was first committed on Oct 09 2019 18:23:24. As a result, documentation below may be outdated.
No ‘How to Implement the Solution’ section available. Please consider contributing.
No ‘How to Run the Solution’ section available. Please consider contributing.