Created
August 24, 2016 16:14
-
-
Save codercodingthecode/9b6a7e1650bf5e232bcf76064790a1b9 to your computer and use it in GitHub Desktop.
Caesars Cipher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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