ROT 13

This code performs ROT 13 encryption
 avatar
theLazyProgrammer
c_cpp
7 months ago
549 B
39
Indexable
Never
/**
 * rot13 - perform ROT13 encryption
 * @s: string to encrypt
 *
 * Return: pointer to the encrypted string @s
 */
char *rot13(char *s)
{
	int i, j;
	const char *map = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM";

	for (i = 0; s[i] != '\0'; i++)
	{
		char ch = s[i];

		if (ch >= 'a' && ch <= 'z')
		{
			j = ch - 'a'; /* get index position for lowercase letters */
			s[i] = map[j];
		}
		else if (ch >= 'A' && ch <= 'Z')
		{
			j = ch - 'A' + 26; /* get index position for uppercase letters */
			s[i] = map[j];
		}
	}
	return (s);
}