Skip to content

Instantly share code, notes, and snippets.

@codercodingthecode
Created August 24, 2016 16:14
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 codercodingthecode/9b6a7e1650bf5e232bcf76064790a1b9 to your computer and use it in GitHub Desktop.
Save codercodingthecode/9b6a7e1650bf5e232bcf76064790a1b9 to your computer and use it in GitHub Desktop.
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