Created
March 5, 2019 09:06
-
-
Save kostandy/de1a151a736edb69ea536a1b87d7a8f9 to your computer and use it in GitHub Desktop.
ROT13 replaces each letter by its partner 13 characters further along the alphabet. For example, HELLO becomes URYYB (or, conversely, URYYB becomes HELLO again). Read more - https://en.wikipedia.org/wiki/ROT13
This file contains 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
const rot13 = message => { | |
const a = message.split(''); | |
return a.map(s => { | |
const c = s.charCodeAt(); | |
if (c <= 65 || c >= 123 || s === ' ') return s; | |
return String.fromCharCode( | |
c <= 78 && c < 90 || c >= 97 && c < 110 ? c+13 : c-13 | |
); | |
}).join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment