Skip to content

Instantly share code, notes, and snippets.

@Unam3dd
Last active October 22, 2021 12:46
Show Gist options
  • Save Unam3dd/76d5452395aaa9e4d744bf9102b17057 to your computer and use it in GitHub Desktop.
Save Unam3dd/76d5452395aaa9e4d744bf9102b17057 to your computer and use it in GitHub Desktop.
Simple ROT13 Cipher
#include <stdio.h>
#define IS_ALPHA(c) ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
char *rot13_cipher(char *dst, char *src)
{
char *tmp = dst;
while (*src) {
if (!IS_ALPHA(*src))
*tmp++ = *src++;
if (*src >= 'a' && *src < 'n' || *src >= 'A' && *src < 'N')
*tmp++ = *src++ + 13;
if (*src >= 'n' && *src <= 'z' || *src >= 'N' && *src <= 'Z')
*tmp++ = *src++ - 13;
}
*tmp = 0;
return (dst);
}
int main(void)
{
char buf[0x100];
rot13_cipher(buf, "h3llo/ W0rld");
printf("%s\n", buf);
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment