Created
March 13, 2018 21:19
-
-
Save christophwolff/743a31828b5ce96c37a13d2b0811835e to your computer and use it in GitHub Desktop.
ROT13 Encode/Decode
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
rot13 (s) { | |
return s.split('').map((_) => { | |
if (!_.match(/[A-Za-z]/)) return _ | |
var c = Math.floor(_.charCodeAt(0) / 97) | |
var k = (_.toLowerCase().charCodeAt(0) - 83) % 26 || 26 | |
return String.fromCharCode(k + ((c === 0) ? 64 : 96)) | |
}).join('') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment