to windlrming (懂了)
1.不明白你贴出这段代码是为什么?
2.看别人没有注释又不知道干什么的C代码实在是件痛苦的事情
3.为了省事,你可以把这段C代码作为PHP模块编译进去(请参考PHP API: 扩展开发接口)
1.不明白你贴出这段代码是为什么?
2.看别人没有注释又不知道干什么的C代码实在是件痛苦的事情
3.为了省事,你可以把这段C代码作为PHP模块编译进去(请参考PHP API: 扩展开发接口)
我今天又改了一下,我感觉自己是正确的,可答案就是不正确,
网吧机子没有软驱,所以没有办法贴出来
<?
/****************************************************************
本程序为一加密程序,已在windows2000server+IIS+php4.0上编译通过
****************************************************************/
if($name!="")
{
$cust_key_1="8Gn_";
$cust_key_2="aoZ1";
$cust_key_3="T]V[";
$cust_key_4="5tbB";
$tlr_key_1="laSG";
$tlr_key_2="|RhV";
$tlr_key_3="jLyd";
$tlr_key_4="9HgU";
function hash_f(&$x,&$y,&$z,$count,&$result )
{
$temp_1=array();
$temp_2=array();
$temp_3=array();
$i=0;
switch ($count)
{
case 0:
for( $i=0; $i<4;$i++ )
{
$tmp_1[$i]=$x[$i]&$y[$i];
$tmp_1[$i]%=256;
$tmp_2[$i]=~$x[$i];
$tmp_2[$i]%=256;
$tmp_3[$i]=$tmp_2[$i]&$z[$i];
$tmp_2[$i]%=256;
$result[$i]=$tmp_1[$i]|$tmp_3[$i];
$result[$i]%=256;
}
break;
case 1:
for( $i=0; $i<4; $i++ )
{
$tmp_1[$i]=$x[$i]^$y[$i];
$tmp_1[$i]%=256;
$result[$i]=$tmp_1[$i]^$z[$i];
$result[$i]%=256;;
}
break;
case 2:
for( $i=0; $i<4; $i++ )
{
$tmp_1[$i]=$x[$i]&$y[$i];
$tmp_1[$i]%=256;
$tmp_2[$i]=$x[$i]&$z[$i];
$tmp_2[$i]%=256;
$tmp_3[$i]=$tmp_1[$i]|$tmp_2[$i];
$tmp_3[$i]%=256;
$tmp_1[$i]=$y[$i]&$z[$i];
$tmp_1[$i]%=256;
$result[$i]=$tmp_1[$i]|$tmp_3[$i];
$result[$i]%=256;
}
break;
case 3:
for( $i=0; $i<4; $i++ )
{
$tmp_1[$i]=$x[$i]^$y[$i];
$result[$i]=$tmp_1[$i]^$z[$i];
$result[$i]%=256;
}
break;
default:
break;
}
return ;
}function hash_circleft(&$str,&$re_str,$count )
{
$temp=0;
$power=0;
$bitstr=array();
for( $i=0; $i<4; $i++ )
{
$temp=$str[$i];
for( $j=7; $j>=0; $j-- )
{
$bitstr[8*$i+$j]=$temp%2;
$temp/=2;
$temp=sprintf("%d",$temp);
}
}
for( $i=0; $i<$count; $i++ )
{
$temp=$bitstr[31];
for( $j=31; $j>0; $j-- )
{
$bitstr[$j]=$bitstr[$j-1];
}
$bitstr[0]=$temp;
} for( $i=0; $i<4; $i++ )
{
$temp=0;
$power=128;
for($j=0; $j<8; $j++ )
{
if($bitstr[8*$i+$j] )
$temp+=$power;
$power/=2;
$power=sprintf("%d",$power);
}
$re_str[$i]=$temp%256;
}
return ;
}function hash_tlr(&$message,&$rresu )
{
global $tlr_key_1,$tlr_key_2,$tlr_key_3,$tlr_key_4;
$init_a=array(0x67,0x45,0x23,0x01);
$init_b=array(0xef,0xcd,0xab,0x89);
$init_c=array(0x98,0xba,0xdc,0xfe);
$init_d=array(0x10,0x32,0x56,0x76);
$init_e=array(0xc3,0xd2,0xe1,0xf0);
$temp_a=array();
$temp_b=array();
$temp_c=array();
$temp_d=array();
$temp_e=array();
$cal_mess=array();
$w=array();
$str_temp=array();
$str_temp1=array();
$resu=array();
$temp_resu=array();
$mlen=strlen($message);
for($i=0;$i<$mlen;$i++)
{
$cal_mess[$i]=ord($message[$i]);
}
$cal_mess[$mlen]=0x80;
for( $i=$mlen+1;$i<63;$i++)
$cal_mess[$i]=0x30;
$cal_mess[63]=$mlen;
for( $i=0; $i<4; $i++ )
{
$temp_a[$i]=$init_a[$i];
$temp_b[$i]=$init_b[$i];
$temp_c[$i]=$init_c[$i];
$temp_d[$i]=$init_d[$i];
$temp_e[$i]=$init_e[$i];
}
for($i=0;$i<64;$i++)
$w[$i]=$cal_mess[$i];
for($i=16;$i<80;$i++)
for($j=0;$j<4;$j++)
{
$str_temp[$j]=(($w[4*($i-3)+$j])^($w[4*($i-8)+$j])%256);
$str_temp[$j]^=($w[4*($i-14)+$j]);
$str_temp[$j]%=256;
$str_temp[$j]^=($w[4*($i-16)+$j]);
$w[4*$i+$j]=$str_temp[$j]%256;;
}
for($i=0;$i<4;$i++ )
{
for($k=20*$i;$k<20*($i+1);$k++ )
{
hash_circleft($init_a,$str_temp,5);
hash_f($init_b,$init_c,$init_d,$i,$str_temp1);
for( $j=0; $j<4; $j++ )
{
$str_temp[$j]+=$str_temp1[$j];
$str_temp[$j]+=$init_e[$j];
$str_temp[$j]%=256;
switch($i)
{
case 0:
$str_temp[$j]+=ord($tlr_key_1[$j]);
break;
case 1:
$str_temp[$j]+=ord($tlr_key_2[$j]);
break;
case 2:
$str_temp[$j]+=ord($tlr_key_3[$j]);
break;
case 3:
$str_temp[$j]+=ord($tlr_key_4[$j]);
break;
default:
break;
}
$str_temp[$j]+=$w[4*$k+$j];
$str_temp[$j]%=256;
}
for($j=0;$j<4;$j++ )
{
$init_e[$j]=$init_d[$j];
$init_d[$j]=$init_c[$j];
}
hash_circleft($init_b,$init_c,25);
for($j=0;$j<4;$j++ )
{
$init_b[$j]=$init_a[$j];
$init_a[$j]=$str_temp[$j];
}
}
} for($i=0;$i<4;$i++ )
{
$temp_a[$i]+=$init_a[$i];
$temp_b[$i]+=$init_b[$i];
$temp_c[$i]+=$init_c[$i];
$temp_d[$i]+=$init_d[$i];
$temp_e[$i]+=$init_e[$i];
}
$temp_a[$i]%=256;
$temp_b[$i]%=256;
$temp_c[$i]%=256;
$temp_d[$i]%=256;
$temp_e[$i]%=256;
$resu[0]=$temp_a[0];
$resu[1]=$temp_c[0];
$resu[2]=$temp_e[0];
for($i=0;$i<4;$i++ )
{
$resu[0]+=$temp_a[$i];
$resu[0]+=$temp_b[$i];
$resu[1]+=$temp_c[$i];
$resu[1]+=$temp_d[$i];
$resu[2]+=$temp_e[$i];
}
$resu[0]%=256;
$resu[0]%=256;
$resu[1]%=256;
$resu[1]%=256;
$resu[2]%=256;
for($i=0;$i<3;$i++ )
{
$temp_resu=sprintf("%02x",$resu[$i]);
$ss.=strval($temp_resu);
}
$rresu=$ss;
echo "<br>\n".$ss;
}
for($i=0;$i<6 And $i<strlen($name);$i++) //加密串最长为6个字符
$message[$i]=$name[$i];
$message=implode("",$message);
echo"要加密的字符串$name<br>\n";
hash_tlr($message,$resu);
echo "加密后的字符串为:".$resu;
echo "<hr>";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>加密</title>
</head><body><form name="form1" method="post" action="<?echo $PHP_SELF;?>">
<p>请输入你要加密的字符:
<input name="name" type="text" id="name">
</p>
<p>
<input type="submit" name="Submit" value="提交">
<input type="reset" name="Submit2" value="重置">
</p>
</form>
</body>
</html>