Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created June 16, 2014 17:47
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 tmcw/2d38a0c20ccf22a4390c to your computer and use it in GitHub Desktop.
Save tmcw/2d38a0c20ccf22a4390c to your computer and use it in GitHub Desktop.
Gist from mistakes.io
function decode(str) {
var id = str.split('');
var pts = [];
while (id.length) { pts.push([id.shift(), id.shift()].join('')) }
return pts.map(function(p) {
return String.fromCharCode(parseInt(p, 16));
}).join('');
}
function encode(str) {
var chars = str.split('');
return chars.map(function(c) {
return c.charCodeAt(0).toString(16);
}).join('');
}
encode('TILE');
decode(encode('TILE'));
decode('45737269');
decode('47503130')
decode('5f4d544e')
decode('42654c6e')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment