Created
August 24, 2016 16:14
Caesars Cipher
This file contains hidden or 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