function rot13(str) { // LBH QVQ VG!
return str.replace(/\w/g, function(letter){
if (str.charCodeAt(str.indexOf(letter)) + 13 > 90) {
return String.fromCharCode(str.charCodeAt(str.indexOf(letter)) - 13);
} else {
return String.fromCharCode(str.charCodeAt(str.indexOf(letter)) + 13);
}
});
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
1 Like