Last active
April 30, 2025 13:54
-
-
Save FlameWolf/3db2939558215a8f08246a8441e15648 to your computer and use it in GitHub Desktop.
ROT18 Implementation in JavaScript
This file contains hidden or 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 rot18 = (() => { | |
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()); | |
} | |
} | |
return 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