Created
June 7, 2011 15:44
-
-
Save tyx/1012518 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
public static function generateShortKey($input) | |
{ | |
$base32 = array ( | |
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', | |
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', | |
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', | |
'y', 'z', '0', '1', '2', '3', '4', '5' | |
); | |
$hex = md5($input); | |
$subHex = substr ($hex, 0, 8); | |
$int = 0x3FFFFFFF & (1 * ('0x'.$subHex)); | |
$out = ''; | |
for ($j = 0; $j < 6; $j++) | |
{ | |
$val = 0x0000001F & $int; | |
$out .= $base32[$val]; | |
$int = $int >> 5; | |
} | |
return $out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment