Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ES6 Awesomeness
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);
@soundyogi

This comment has been minimized.

Copy link

commented Dec 5, 2016

awesome!

[].map.call would be even shorter!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.