Last active
October 22, 2021 12:46
-
-
Save Unam3dd/76d5452395aaa9e4d744bf9102b17057 to your computer and use it in GitHub Desktop.
Simple ROT13 Cipher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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