Skip to content

Instantly share code, notes, and snippets.

@cookiengineer
Created December 5, 2016 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cookiengineer/77b59f623a8056fd64db67be993446da to your computer and use it in GitHub Desktop.
Save cookiengineer/77b59f623a8056fd64db67be993446da to your computer and use it in GitHub Desktop.
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
Copy link

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