Created
December 23, 2014 21:48
-
-
Save trcio/389a205a8476ff93ab04 to your computer and use it in GitHub Desktop.
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
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