Rumah >pembangunan bahagian belakang >tutorial php >懂PHP且懂点C的大神进去
懂PHP且懂点C的大神进来
这是个客户端C版本的解密函数,我需要一个PHP版本的加密函数,麻烦下大神,
<br />void hdth_normal_decode(char * outstr,char * instr)<br />{<br /> int i=0;<br /> int j = 0;<br /> int len = strlen(instr);<br /> for(i=0;i<len;i=i+2) <br /> { <br /> int h=(instr[i]-'c'); <br /> int l=(instr[i+1]-'f'); <br /> char c=(l<<4)+(h&0xf); <br /> outstr[j]=c;<br /> j++;<br /> } <br /><br /> return;<br />}<br />
<br />原文:www.comunits.net<br />密文:jmjmjmqhflrlplhmqlllgmfmqhqlhlgm<br />
function hdth_normal_decode($in) {<br /> $out = ''; <br /> $len = strlen($in);<br /> for($i=0; $i<$len; $i+=2) {<br /> $h = ord($in{$i}) - ord('c');<br /> $l = ord($in{$i+1}) - ord('f');<br /> $c = ($l << 4) + ($h & 0xf);<br /> $out .= chr($c);<br /> }<br /> return $out;<br />}然后求其逆运算
function hdth_normal_encode($in) {<br /> $out = '';<br /> $len = strlen($in);<br /> for($i=0; $i<$len; $i++) {<br /> $c = ord($in{$i});<br /> $l = ($c >> 4) + ord('f');<br /> $h = ($c & 0xf) + ord('c');<br /> $out .= chr($h) . chr($l);<br /> }<br /> return $out;<br />}测试一下
echo hdth_normal_encode('www.comunits.net');jmjmjmqhflrlplhmqlllgmfmqhqlhlgm