Skip to content

Instantly share code, notes, and snippets.

@trcio
Created December 23, 2014 21:48
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 trcio/389a205a8476ff93ab04 to your computer and use it in GitHub Desktop.
Save trcio/389a205a8476ff93ab04 to your computer and use it in GitHub Desktop.
function getKey(identifier) {
var chars = '0123456789ABCDEFGHJKLMNPQRTUVWXY',
hash = CryptoJS.MD5(identifier).toString().toUpperCase(),
parts = [];
for (var i = 0; i < 32; i += 2) {
var nextDigit = parseInt(hash.substr(i, 2), 16) & 31,
withDash = (((i % 8) == 0) && (i > 0));
parts.push(withDash ? '-' : '');
parts.push(chars.substr(nextDigit, 1));
}
return {id: identifier, key:parts.join('')};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment