Skip to content

Instantly share code, notes, and snippets.

@korniychuk
Created January 23, 2017 10:57
Show Gist options
  • Save korniychuk/53000cd01937908610a380fef9566f72 to your computer and use it in GitHub Desktop.
Save korniychuk/53000cd01937908610a380fef9566f72 to your computer and use it in GitHub Desktop.
Encode any string to hex codes and decode back
let str = 'My Secure String';
let enc = str.split('').map(char => '0x'+char.codePointAt(0).toString(16)).join(' ');
let dec = enc.split(' ').map(code => String.fromCodePoint(parseInt(code))).join('')
console.log(`Encoded: '${enc}'`);
console.log(`'${str}' === '${dec}'`, str === dec);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment