3 int stringLength(const char* str
) {
6 while (str
[result
] != '\0') {
13 void swap(char* v1
, char* v2
) {
19 void reverseString(char* str
) {
20 int length
= stringLength(str
);
21 int halfLength
= length
/ 2;
23 for (int charId
= 0; charId
< halfLength
; ++charId
) {
24 swap(&str
[charId
], &str
[length
- charId
- 1]);
28 /** Perform a classical ROT13 permutation in-place */
29 void rot13(char* str
) {
30 int length
= stringLength(str
);
32 for (int charId
= 0; charId
< length
; ++charId
) {
33 char chrValue
= str
[charId
];
35 if (chrValue
>= 'a' && chrValue
<= 'z') {
37 (chrValue
- 'a' // Translate chrValue from 'a'-'z' to 0-25
39 % 26 // Rotate in 0-25
40 + 'a'; // Translate the value from 0-25 to 'a'-'z'
41 } else if (chrValue
>= 'A' && chrValue
<= 'Z') {
42 str
[charId
] = (chrValue
- 'A' + 13) % 26 + 'A';
48 char msg
[] = "Votre message";
49 printf("Initial value: \"%s\"\n", msg
);
51 printf("Reversed : \"%s\"\n", msg
);
52 reverseString(msg
); // Restore the original message
54 printf("ROT13 : \"%s\"\n", msg
);