Skip to content

Instantly share code, notes, and snippets.

@tyx
Created June 7, 2011 15:44
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 tyx/1012518 to your computer and use it in GitHub Desktop.
Save tyx/1012518 to your computer and use it in GitHub Desktop.
<?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