Created
May 23, 2015 14:06
-
-
Save raganwald/5ab12adc34b4d9a30f42 to your computer and use it in GitHub Desktop.
Secret Decoder Ring
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 SecretDecoderRing = { | |
encode: function (plaintext) { | |
return plaintext | |
.split('') | |
.map( char => char.charCodeAt() ) | |
.map( code => code + 1 ) | |
.map( code => String.fromCharCode(code) ) | |
.join(''); | |
}, | |
decode: function (cyphertext) { | |
return cyphertext | |
.split('') | |
.map( char => char.charCodeAt() ) | |
.map( code => code - 1 ) | |
.map( code => String.fromCharCode(code) ) | |
.join(''); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Want to learn the latest cryptography techniques... in JavaScript?
JavaScript Allongé, the “Six” Edition has you covered!