Skip to content

Instantly share code, notes, and snippets.

@entyo
Last active May 28, 2018 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save entyo/8d2368654024e159e742ae35cb80e840 to your computer and use it in GitHub Desktop.
Save entyo/8d2368654024e159e742ae35cb80e840 to your computer and use it in GitHub Desktop.
ROT13 decoder
function genLookUpTable(k: string, v: string) {
return k.split('').map((c, i) => { return { [c]: v[i] } }).reduce((a, c) => Object.assign(a, c))
}
function decodeROT13(code: string): string {
// https://www.wikiwand.com/ja/ROT13#/%E5%AF%BE%E7%85%A7%E8%A1%A8%E3%81%AB%E3%82%88%E3%82%8B%E5%AE%9F%E8%A3%85
const lookupTable = genLookUpTable(
'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm',
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
);
return code.split('').map(c => lookupTable[c]).join('')
}
// HATENA
console.log(decodeROT13('UNGRAN'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment