Skip to content

Instantly share code, notes, and snippets.

@kostandy
Created March 5, 2019 09:06
Show Gist options
  • Save kostandy/de1a151a736edb69ea536a1b87d7a8f9 to your computer and use it in GitHub Desktop.
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
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