Skip to content

Instantly share code, notes, and snippets.

@tfeldmann
Last active July 9, 2020 09:22
Show Gist options
  • Save tfeldmann/cb511d9e1c8fcddd3288abfb25f1f366 to your computer and use it in GitHub Desktop.
Save tfeldmann/cb511d9e1c8fcddd3288abfb25f1f366 to your computer and use it in GitHub Desktop.
ROT18 implementation in python and c
void rot18(char *c)
{
while (*c)
{
if (*c >= 'A' && *c <= 'Z')
*c = ('A' + (*c - 'A' + 13) % 26);
else if (*c >= 'a' && *c <= 'z')
*c = ('a' + (*c - 'a' + 13) % 26);
else if (*c >= '0' && *c <= '9')
*c = ('0' + (*c - '0' + 5) % 10);
c++;
}
}
ROT18 = str.maketrans(
"ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz0123456789",
"NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm5678901234",
)
def rot18(text):
return text.translate(ROT18)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment