Created
December 5, 2016 01:07
-
-
Save cookiengineer/77b59f623a8056fd64db67be993446da to your computer and use it in GitHub Desktop.
ES6 Awesomeness
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
const _DICTIONARY = new Array(96).fill('').map((a,v) => String.fromCharCode(32 + v)); | |
const _encode_rot32 = function(string) { | |
return Array.prototype.map.call(string, val => _DICTIONARY[(32 + _DICTIONARY.indexOf(val)) % _DICTIONARY.length]).join(''); | |
}; | |
const _decode_rot32 = function(string) { | |
return Array.prototype.map.call(string, val => _DICTIONARY[(_DICTIONARY.indexOf(val) - 32 + _DICTIONARY.length) % _DICTIONARY.length]).join(''); | |
}; | |
// Usage | |
_encode_rot32('hello world'); | |
let secret = _encode_rot32('hello world'); | |
let plain = _decode_rot32(secret); | |
console.log(secret); | |
console.log(plain); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
awesome!
[].map.call would be even shorter!