Instantly share code, notes, and snippets.

@entyo /i_love_onsya.ts Secret
Last active May 28, 2018

Embed
What would you like to do?
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