Last active
March 23, 2017 13:45
-
-
Save aledwassell/758d669f06a1a0a3ffe8775c298b2724 to your computer and use it in GitHub Desktop.
This was the free code camps Caesar's Cipher, hard but I did it, not sure why it doesn't work though
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! | |
str = str.toUpperCase().split(''); | |
str.reduce(function(acc, item) { | |
var patt = /[a-zA-Z]/g; | |
if(patt.test(item)){ | |
item = item.charCodeAt(0); | |
if(item > 77) { | |
return acc + String.fromCharCode(item - 13); | |
} else if (item < 78){ | |
return acc + String.fromCharCode(item + 13); | |
} | |
} else { | |
return acc + item; | |
} | |
},[]); | |
} | |
// Change the inputs below to test | |
rot13("GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment