用PHP写的MD5加密函数
//php_md5("字符串")
define("BITS_TO_A_BYTE",8);
define("BYTES_TO_A_WORD",4);
define("BITS_TO_A_WORD",32);
$m_lOnBits=array(30);
$m_l2Power=array(30);
function LShift($lValue,$iShiftBits)
{
if ($iShiftBits==0) return $lValue;
if ($iShiftBits==31)
{
if ($lValue&1) { return 0x80000000; }
else { return 0; }
}
if ($iShiftBits < 0 || $iShiftBits > 31) { }
if (($lValue&$GLOBALS[31-$iShiftBits]))
{ $tmpstr=(($lValue&$GLOBALS[31-($iShiftBits+1)])*$GLOBALS[$iShiftBits])|0x80000000; }
else
{ $tmpstr=(($lValue&$GLOBALS[31-$iShiftBits])*$GLOBALS[$iShiftBits]); }
return $tmpstr;
}
function RShift($lValue,$iShiftBits)
{
if ($iShiftBits==0)return $lValue;
if ($iShiftBits==31)
{
if ($lValue&0x80000000) { return 1; }
else { return 0; }
}
if ($iShiftBits<0 || $iShiftBits>31) { }
$tmpstr=floor(($lValue&0x7FFFFFFE)/$GLOBALS[$iShiftBits]);
if ($lValue&0x80000000) { $tmpstr=$tmpstr|floor(0x40000000/$GLOBALS[$iShiftBits-1]); }
return $tmpstr;
}
function RotateLeft($lValue,$iShiftBits)
{
return LShift($lValue,$iShiftBits)|RShift($lValue,(32-$iShiftBits));
}
function AddUnsigned($lX,$lY)
{
$lX8=$lX&0x80000000;
$lY8=$lY&0x80000000;
$lX4=$lX&0x40000000;
$lY4=$lY&0x40000000;
$lResult=($lX&0x3FFFFFFF)+($lY&0x3FFFFFFF);
if ($lX4&$lY4) { $lResult=$lResult^0x80000000^$lX8^$lY8; }
if ($lX4|$lY4)
{
if ($lResult&0x40000000)
{ $lResult=$lResult^0xC0000000^$lX8^$lY8; }
else
{ $lResult=$lResult^0x40000000^$lX8^$lY8; }
}
else
{ $lResult=$lResult^$lX8^$lY8; }
return $lResult;
}
function md5_F($x,$y,$z)
{
return ($x&$y)|((~$x)&$z);
本文章更多内容:1 - 2 - 3 - 4 - 5 - 6 - 下一页>> |