Skip to content

Instantly share code, notes, and snippets.

@christophwolff
Created March 13, 2018 21:19
Show Gist options
  • Save christophwolff/743a31828b5ce96c37a13d2b0811835e to your computer and use it in GitHub Desktop.
Save christophwolff/743a31828b5ce96c37a13d2b0811835e to your computer and use it in GitHub Desktop.
ROT13 Encode/Decode
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