[COLUG] Enterprise Two Factor Authentication: $j=hexdec(md5($j));
Jim
jep200404 at columbus.rr.com
Tue Mar 13 18:24:07 EST 2007
On Wed, 14 Mar 2007 09:45:06 +1100 Duane <duane at cacert.org> wrote:
> [binary output from md5()] only became an option in php5
> and later and a lot of php servers out there still use php4 or
> even 3 in some cases.
OK.
Even so, since we know that length of the output of md5sum fits
in a 32-bit int, I still see simplification:
function encode($j,$nBitsPerEncodedChar,$encoding)
{
if (strlen($encoding)!=(1<<$nBitsPerEncodedChar)) {
echo stderr "strlen(\"$encoding\")!=(1<<$nBitsPerEncodedChar)\n";
exit(EXIT_FAILURE);
}
$j=hexdec(md5($j));
/* Each loop converts $nBitsPerEncodedChar least significant bits of $j
* to character from $encoding. */
$s="";
for ($i=32;$i>0;$i-=$nBitsPerEncodedChar) {
$s=$encoding[$j & ((1<<$nBitsPerEncodedChar)-1)].$s;
$j>>=$nBitsPerEncodedChar;
$j&=((1<<$i)-1); /* to avoid issue of possible arithmetic shift right filling with 1s */
}
return $s;
}
More information about the colug432
mailing list