1 /*********************************************************************
3 * Author: Brad Conte (brad AT bradconte.com)
5 * Disclaimer: This code is presented "as is" without any guarantees.
6 * Details: Implementation of the ROT-13 encryption algorithm.
7 Algorithm specification can be found here:
9 This implementation uses little endian byte order.
10 *********************************************************************/
12 /*************************** HEADER FILES ***************************/
16 /*********************** FUNCTION DEFINITIONS ***********************/
17 void rot13(char str[])
19 int case_type, idx, len;
21 for (idx = 0, len = strlen(str); idx < len; idx++) {
22 // Only process alphabetic characters.
23 if (str[idx] < 'A' || (str[idx] > 'Z' && str[idx] < 'a') || str[idx] > 'z')
25 // Determine if the char is upper or lower case.
30 // Rotate the char's value, ensuring it doesn't accidentally "fall off" the end.
31 str[idx] = (str[idx] + 13) % (case_type + 26);
33 str[idx] += case_type;