Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Caesars Cipher
function rot13(str) { // LBH QVQ VG!
var newArr = [];
var final = [];
for (var i = 0; i < str.length; i++) {
newArr[i] = (str.charCodeAt(i));
if (newArr[i] >= 65 && newArr[i] <= 77) {
newArr[i] += 13;
}
else if (newArr[i] >=78 && newArr[i] <= 90) {
newArr[i] -= 13;
}
final[i] = String.fromCharCode(newArr[i]);
}
return final.join('');
}
console.log(rot13("LBH QVQ VG!"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.