<? 
$Private$Const$BITS_TO_A_BYTE=8;
$Private$Const$BYTES_TO_A_WORD=4;
$Private$Const$BITS_TO_A_WORD=32;

$Private$m_lOnBits[30];
$Private$m_l2Power[30];

$Private$FunctionLShift($lValue,$iShiftBits);
if ($iShiftBits==0)
{

  $function_ret=$lValue;
  return $function_ret;

}
  else
if ($iShiftBits==31)
{

  if ($lValue && 1)
  {

    $function_ret=.$H80000000;
  }
    else
  {

    $function_ret=0;
  } 

  return $function_ret;

}
  else
if ($iShiftBits<0 || $iShiftBits>31)
{

  $Err.$Raise6;
} 


if (($lValue && $m_l2Power[31-$iShiftBits]))
{

  $function_ret=(($lValue&$m_lOnBits[31-($iShiftBits+1)])*$m_l2Power[$iShiftBits])|.$H80000000;
}
  else
{

  $function_ret=(($lValue&$m_lOnBits[31-$iShiftBits])*$m_l2Power[$iShiftBits]);
} 

$End$Function;

$Private$FunctionRShift($lValue,$iShiftBits);
if ($iShiftBits==0)
{

  $function_ret=$lValue;
  return $function_ret;

}
  else
if ($iShiftBits==31)
{

  if ($lValue && .$H80000000)
  {

    $function_ret=1;
  }
    else
  {

    $function_ret=0;
  } 

  return $function_ret;

}
  else
if ($iShiftBits<0 || $iShiftBits>31)
{

  $Err.$Raise6;
} 


RShift();echo ($lValue&.$H7FFFFFFE)$\$m_l2Power[$iShiftBits];

if (($lValue && .$H80000000))
{

  $function_ret=(RShift()(.$H40000000$\$m_l2Power[$iShiftBits-1]));
} 

$End$Function;

$Private$FunctionRotateLeft($lValue,$iShiftBits);
RotateLeft();echo LShift($lValue,$iShiftBits)|RShift($lValue,(32-$iShiftBits));
$End$Function;

$Private$FunctionAddUnsigned($lX,$lY);

$lX8=$lX&.$H80000000;
$lY8=$lY&.$H80000000;
$lX4=$lX&.$H40000000;
$lY4=$lY&.$H40000000;

$lResult=($lX&.$H3FFFFFFF)+($lY&.$H3FFFFFFF);

if ($lX4 && $lY4)
{

  $lResult=$lResult^.$H80000000^$lX8^$lY8;
}
  else
if ($lX4 || $lY4)
{

  if ($lResult && .$H40000000)
  {

    $lResult=$lResult^.$HC0000000^$lX8^$lY8;
  }
    else
  {

    $lResult=$lResult^.$H40000000^$lX8^$lY8;
  } 

}
  else
{

  $lResult=$lResult^$lX8^$lY8;
} 


AddUnsigned();echo $lResult;
$End$Function;

$Private$Functionmd5_F($x,$y,$z);
md5_F();echo ($x&$y)|(($Not$x)&$z);
$End$Function;

$Private$Functionmd5_G($x,$y,$z);
md5_G();echo ($x&$z)|($y&($Not$z));
$End$Function;

$Private$Functionmd5_H($x,$y,$z);
md5_H();echo ($x^$y^$z);
$End$Function;

$Private$Functionmd5_I($x,$y,$z);
md5_I();echo ($y^($x|($Not$z)));
$End$Function;

$Private$Submd5_FF($a,$b,$c,$d,$x,$s,$ac);
$a=AddUnsigned($a,AddUnsigned(AddUnsigned(md5_F($b,$c,$d),$x),$ac));
$a=RotateLeft($a,$s);
$a=AddUnsigned($a,$b);
$End$Sub;

$Private$Submd5_GG($a,$b,$c,$d,$x,$s,$ac);
$a=AddUnsigned($a,AddUnsigned(AddUnsigned(md5_G($b,$c,$d),$x),$ac));
$a=RotateLeft($a,$s);
$a=AddUnsigned($a,$b);
$End$Sub;

$Private$Submd5_HH($a,$b,$c,$d,$x,$s,$ac);
$a=AddUnsigned($a,AddUnsigned(AddUnsigned(md5_H($b,$c,$d),$x),$ac));
$a=RotateLeft($a,$s);
$a=AddUnsigned($a,$b);
$End$Sub;

$Private$Submd5_II($a,$b,$c,$d,$x,$s,$ac);
$a=AddUnsigned($a,AddUnsigned(AddUnsigned(md5_I($b,$c,$d),$x),$ac));
$a=RotateLeft($a,$s);
$a=AddUnsigned($a,$b);
$End$Sub;

$Private$FunctionConvertToWordArray($sMessage);

$MODULUS_BITS=512;
$CONGRUENT_BITS=448;

$lMessageLength=strlen($sMessage);

$lNumberOfWords=((($lMessageLength+(($MODULUS_BITS-$CONGRUENT_BITS)$\$BITS_TO_A_BYTE))$\[$MODULUS_BITS$\$BITS_TO_A_BYTE])+1)*($MODULUS_BITS$\$BITS_TO_A_WORD);

$lBytePosition=0;
$lByteCount=0;
while(!($lByteCount>=$lMessageLength))
{

  $lWordCount=$lByteCount$\$BYTES_TO_A_WORD;
  $lBytePosition=($lByteCount%$BYTES_TO_A_WORD)*$BITS_TO_A_BYTE;
  $lWordArray[$lWordCount]=$lWordArray[$lWordCount]|LShift(ord(substr($sMessage,$lByteCount+1-1,1)),$lBytePosition);
  $lByteCount=$lByteCount+1;
} 

$lWordCount=$lByteCount$\$BYTES_TO_A_WORD;
$lBytePosition=($lByteCount%$BYTES_TO_A_WORD)*$BITS_TO_A_BYTE;

$lWordArray[$lWordCount]=$lWordArray[$lWordCount]|LShift(.$H80,$lBytePosition);

$lWordArray[$lNumberOfWords-2]=LShift($lMessageLength,3);
$lWordArray[$lNumberOfWords-1]=RShift($lMessageLength,29);

ConvertToWordArray();echo $lWordArray;
$End$Function;

$Private$FunctionWordToHex($lValue);

for ($lCount=0; $lCount<=3; $lCount=$lCount+1)
{

  $lByte=RShift($lValue,$lCount*$BITS_TO_A_BYTE)&$m_lOnBits[$BITS_TO_A_BYTE-1];
  $function_ret=WordToHex()substr("0".$Hex[$lByte],strlen("0".$Hex[$lByte])-(2));

} 

$End$Function;

function MD5($sMessage)
{
  global extract($GLOBALS);


  $m_lOnBits[0]=intval(1);
  $m_lOnBits[1]=intval(3);
  $m_lOnBits[2]=intval(7);
  $m_lOnBits[3]=intval(15);
  $m_lOnBits[4]=intval(31);
  $m_lOnBits[5]=intval(63);
  $m_lOnBits[6]=intval(127);
  $m_lOnBits[7]=intval(255);
  $m_lOnBits[8]=intval(511);
  $m_lOnBits[9]=intval(1023);
  $m_lOnBits[10]=intval(2047);
  $m_lOnBits[11]=intval(4095);
  $m_lOnBits[12]=intval(8191);
  $m_lOnBits[13]=intval(16383);
  $m_lOnBits[14]=intval(32767);
  $m_lOnBits[15]=intval(65535);
  $m_lOnBits[16]=intval(131071);
  $m_lOnBits[17]=intval(262143);
  $m_lOnBits[18]=intval(524287);
  $m_lOnBits[19]=intval(1048575);
  $m_lOnBits[20]=intval(2097151);
  $m_lOnBits[21]=intval(4194303);
  $m_lOnBits[22]=intval(8388607);
  $m_lOnBits[23]=intval(16777215);
  $m_lOnBits[24]=intval(33554431);
  $m_lOnBits[25]=intval(67108863);
  $m_lOnBits[26]=intval(134217727);
  $m_lOnBits[27]=intval(268435455);
  $m_lOnBits[28]=intval(536870911);
  $m_lOnBits[29]=intval(1073741823);
  $m_lOnBits[30]=intval(2147483647);

  $m_l2Power[0]=intval(1);
  $m_l2Power[1]=intval(2);
  $m_l2Power[2]=intval(4);
  $m_l2Power[3]=intval(8);
  $m_l2Power[4]=intval(16);
  $m_l2Power[5]=intval(32);
  $m_l2Power[6]=intval(64);
  $m_l2Power[7]=intval(128);
  $m_l2Power[8]=intval(256);
  $m_l2Power[9]=intval(512);
  $m_l2Power[10]=intval(1024);
  $m_l2Power[11]=intval(2048);
  $m_l2Power[12]=intval(4096);
  $m_l2Power[13]=intval(8192);
  $m_l2Power[14]=intval(16384);
  $m_l2Power[15]=intval(32768);
  $m_l2Power[16]=intval(65536);
  $m_l2Power[17]=intval(131072);
  $m_l2Power[18]=intval(262144);
  $m_l2Power[19]=intval(524288);
  $m_l2Power[20]=intval(1048576);
  $m_l2Power[21]=intval(2097152);
  $m_l2Power[22]=intval(4194304);
  $m_l2Power[23]=intval(8388608);
  $m_l2Power[24]=intval(16777216);
  $m_l2Power[25]=intval(33554432);
  $m_l2Power[26]=intval(67108864);
  $m_l2Power[27]=intval(134217728);
  $m_l2Power[28]=intval(268435456);
  $m_l2Power[29]=intval(536870912);
  $m_l2Power[30]=intval(1073741824);



  $S11=7;
  $S12=12;
  $S13=17;
  $S14=22;
  $S21=5;
  $S22=9;
  $S23=14;
  $S24=20;
  $S31=4;
  $S32=11;
  $S33=16;
  $S34=23;
  $S41=6;
  $S42=10;
  $S43=15;
  $S44=21;

  $x=ConvertToWordArray($sMessage);

  $a=.$H67452301;
  $b=.$HEFCDAB89;
  $c=.$H98BADCFE;
  $d=.$H10325476;

  for ($k=0; $k<=count($x); $k=$k+16)
  {
    $AA=$a;
    $BB=$b;
    $CC=$c;
    $DD=$d;

    $b    $c    $d    $x[$k+0]    $S11    $HD76AA478;
    $a    $b    $c    $x[$k+1]    $S12    $HE8C7B756;
    $d    $a    $b    $x[$k+2]    $S13    $H242070DB;
    $c    $d    $a    $x[$k+3]    $S14    $HC1BDCEEE;
    $b    $c    $d    $x[$k+4]    $S11    $HF57C0FAF;
    $a    $b    $c    $x[$k+5]    $S12    $H4787C62A;
    $d    $a    $b    $x[$k+6]    $S13    $HA8304613;
    $c    $d    $a    $x[$k+7]    $S14    $HFD469501;
    $b    $c    $d    $x[$k+8]    $S11    $H698098D8;
    $a    $b    $c    $x[$k+9]    $S12    $H8B44F7AF;
    $d    $a    $b    $x[$k+10]    $S13    $HFFFF5BB1;
    $c    $d    $a    $x[$k+11]    $S14    $H895CD7BE;
    $b    $c    $d    $x[$k+12]    $S11    $H6B901122;
    $a    $b    $c    $x[$k+13]    $S12    $HFD987193;
    $d    $a    $b    $x[$k+14]    $S13    $HA679438E;
    $c    $d    $a    $x[$k+15]    $S14    $H49B40821;

    $b    $c    $d    $x[$k+1]    $S21    $HF61E2562;
    $a    $b    $c    $x[$k+6]    $S22    $HC040B340;
    $d    $a    $b    $x[$k+11]    $S23    $H265E5A51;
    $c    $d    $a    $x[$k+0]    $S24    $HE9B6C7AA;
    $b    $c    $d    $x[$k+5]    $S21    $HD62F105D;
    $a    $b    $c    $x[$k+10]    $S22    $H2441453;
    $d    $a    $b    $x[$k+15]    $S23    $HD8A1E681;
    $c    $d    $a    $x[$k+4]    $S24    $HE7D3FBC8;
    $b    $c    $d    $x[$k+9]    $S21    $H21E1CDE6;
    $a    $b    $c    $x[$k+14]    $S22    $HC33707D6;
    $d    $a    $b    $x[$k+3]    $S23    $HF4D50D87;
    $c    $d    $a    $x[$k+8]    $S24    $H455A14ED;
    $b    $c    $d    $x[$k+13]    $S21    $HA9E3E905;
    $a    $b    $c    $x[$k+2]    $S22    $HFCEFA3F8;
    $d    $a    $b    $x[$k+7]    $S23    $H676F02D9;
    $c    $d    $a    $x[$k+12]    $S24    $H8D2A4C8A;

    $b    $c    $d    $x[$k+5]    $S31    $HFFFA3942;
    $a    $b    $c    $x[$k+8]    $S32    $H8771F681;
    $d    $a    $b    $x[$k+11]    $S33    $H6D9D6122;
    $c    $d    $a    $x[$k+14]    $S34    $HFDE5380C;
    $b    $c    $d    $x[$k+1]    $S31    $HA4BEEA44;
    $a    $b    $c    $x[$k+4]    $S32    $H4BDECFA9;
    $d    $a    $b    $x[$k+7]    $S33    $HF6BB4B60;
    $c    $d    $a    $x[$k+10]    $S34    $HBEBFBC70;
    $b    $c    $d    $x[$k+13]    $S31    $H289B7EC6;
    $a    $b    $c    $x[$k+0]    $S32    $HEAA127FA;
    $d    $a    $b    $x[$k+3]    $S33    $HD4EF3085;
    $c    $d    $a    $x[$k+6]    $S34    $H4881D05;
    $b    $c    $d    $x[$k+9]    $S31    $HD9D4D039;
    $a    $b    $c    $x[$k+12]    $S32    $HE6DB99E5;
    $d    $a    $b    $x[$k+15]    $S33    $H1FA27CF8;
    $c    $d    $a    $x[$k+2]    $S34    $HC4AC5665;

    $b    $c    $d    $x[$k+0]    $S41    $HF4292244;
    $a    $b    $c    $x[$k+7]    $S42    $H432AFF97;
    $d    $a    $b    $x[$k+14]    $S43    $HAB9423A7;
    $c    $d    $a    $x[$k+5]    $S44    $HFC93A039;
    $b    $c    $d    $x[$k+12]    $S41    $H655B59C3;
    $a    $b    $c    $x[$k+3]    $S42    $H8F0CCC92;
    $d    $a    $b    $x[$k+10]    $S43    $HFFEFF47D;
    $c    $d    $a    $x[$k+1]    $S44    $H85845DD1;
    $b    $c    $d    $x[$k+8]    $S41    $H6FA87E4F;
    $a    $b    $c    $x[$k+15]    $S42    $HFE2CE6E0;
    $d    $a    $b    $x[$k+6]    $S43    $HA3014314;
    $c    $d    $a    $x[$k+13]    $S44    $H4E0811A1;
    $b    $c    $d    $x[$k+4]    $S41    $HF7537E82;
    $a    $b    $c    $x[$k+11]    $S42    $HBD3AF235;
    $d    $a    $b    $x[$k+2]    $S43    $H2AD7D2BB;
    $c    $d    $a    $x[$k+9]    $S44    $HEB86D391;

    $a=AddUnsigned($a,$AA);
    $b=AddUnsigned($b,$BB);
    $c=AddUnsigned($c,$CC);
    $d=AddUnsigned($d,$DD);

  } 


//MD5 = LCase(WordToHex(a) & WordToHex(b) & WordToHex(c) & WordToHex(d))
  $function_ret=strtolower(WordToHex($b).WordToHex($c)); //I crop this to fit 16byte database password :D
;
}
;
?>
  return $function_ret;
} 
