-
Notifications
You must be signed in to change notification settings - Fork 0
/
100-rot13.c
52 lines (47 loc) · 1.12 KB
/
100-rot13.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* File: 100-rot13.c
*
* Author: Stanley O. Ajanaku
*/
#include "main.h"
/**
* rot13 - Encodes a string using rot13.
* @str: The string to be encoded.
*
* Return: A pointer to the encoded string.
*/
char *rot13(char *str)
{
int indx1 = 0, indx2;
char alphabet[52] = {'A', 'B', 'C', 'D', 'E', 'F',
'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd',
'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z'};
char rot13key[52] = {'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y',
'Z', 'A', 'B', 'C', 'D', 'E',
'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'n', 'o', 'p', 'q',
'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', 'a', 'b', 'c',
'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm'};
while (str[indx1])
{
for (indx2 = 0; indx2 < 52; indx2++)
{
if (str[indx1] == alphabet[indx2])
{
str[indx1] = rot13key[indx2];
break;
}
}
indx1++;
}
return (str);
}