Last active
January 22, 2025 06:17
-
-
Save FlameWolf/3db2939558215a8f08246a8441e15648 to your computer and use it in GitHub Desktop.
ROT18 Implementation in JavaScript
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
const forward = "ABCDEFGHIJKLM01234"; | |
const reverse = "NOPQRSTUVWXYZ56789"; | |
const charMap = new Map(); | |
for (let loopIndex = 0; loopIndex < 18; loopIndex++) { | |
const key = forward[loopIndex]; | |
const val = reverse[loopIndex]; | |
charMap.set(key, val); | |
charMap.set(val, key); | |
if (/\D/.test(key)) { | |
charMap.set(key.toLowerCase(), val.toLowerCase()); | |
charMap.set(val.toLowerCase(), key.toLowerCase()); | |
} | |
} | |
const rot18 = input => input.replace(/\w/gu, char => charMap.get(char) ?? char); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment