Created
March 18, 2016 22:02
-
-
Save ezy/63b58621880b8c99ac41 to your computer and use it in GitHub Desktop.
Caeser Cipher rough
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 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