Skip to content

Instantly share code, notes, and snippets.

@aledwassell
Last active March 23, 2017 13:45
Show Gist options
  • Save aledwassell/758d669f06a1a0a3ffe8775c298b2724 to your computer and use it in GitHub Desktop.
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
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