Home > Backend Development > PHP Tutorial > 懂PHP且懂点C的大神进去

懂PHP且懂点C的大神进去

WBOY
Release: 2016-06-13 12:03:08
Original
974 people have browsed it

懂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 />
Copy after login


给个原文转为密文的例子:

<br />原文:www.comunits.net<br />密文:jmjmjmqhflrlplhmqlllgmfmqhqlhlgm<br />
Copy after login

------解决方案--------------------
先移植解密函数到 php
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 />}
Copy after login
然后求其逆运算
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 />}
Copy after login
测试一下
echo hdth_normal_encode('www.comunits.net');
Copy after login
jmjmjmqhflrlplhmqlllgmfmqhqlhlgm

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template