Created
January 23, 2017 10:57
-
-
Save korniychuk/53000cd01937908610a380fef9566f72 to your computer and use it in GitHub Desktop.
Encode any string to hex codes and decode back
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
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