Quick actions

cmd+k|ctrl+k

Navigation

Languages

rot13 cipher

Snippet info

Language

JavaScript

Visibility

public

Author

diemention

Created

2020-06-23T19:10:29Z

Updated

2020-06-23T19:10:29Z

let input     = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
let output    = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm';

let encoded = ''
let str = 'abcd'

for(let i=0; i<str.length; i++) {
    const index = input.indexOf(str[i])
    encoded += output[index]
}
console.log(encoded)


const rot13 = str => str.split('')
.map(char => String.fromCharCode(
    char.charCodeAt(0) + (char.toLowerCase() < 'n' ? 13 : -13)))
.join("")

x = rot13('abcd')
console.log(x)
    
INFO