Skip to content

Instantly share code, notes, and snippets.

@ezy
Created March 18, 2016 22:02
Show Gist options
  • Select an option

  • Save ezy/63b58621880b8c99ac41 to your computer and use it in GitHub Desktop.

Select an option

Save ezy/63b58621880b8c99ac41 to your computer and use it in GitHub Desktop.
Caeser Cipher rough
function rot13(str) { // LBH QVQ VG!
var result = [],
rotdex = str.split(''),
charcode;
for (i = 0; i < rotdex.length; i++) {
charcode = (rotdex[i].charCodeAt() - 13);
if ((charcode + 13) == 32 || (charcode + 13) == 33 || (charcode + 13) == 46 || (charcode + 13) == 63) {
result.push(String.fromCharCode(charcode + 13));
}
else if ((charcode >= 65) && (charcode <= 90)) {
result.push(String.fromCharCode(charcode));
}
else {
result.push(String.fromCharCode(charcode + 26));
}
}
console.log(result);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment