懂PHP且懂点C的大神进来

WBOY
Release: 2016-06-23 13:53:07
Original
1157 people have browsed it

这是个客户端C版本的解密函数,我需要一个PHP版本的加密函数,麻烦下大神,

void hdth_normal_decode(char * outstr,char * instr){	int   i=0;	int j = 0;	int len = strlen(instr);	for(i=0;i<len;i=i+2)   	{   		int   h=(instr[i]-'c');   		int   l=(instr[i+1]-'f');   		char  c=(l<<4)+(h&0xf);   		outstr[j]=c;		j++;	}   	return;}
Copy after login


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

原文:www.comunits.net密文:jmjmjmqhflrlplhmqlllgmfmqhqlhlgm
Copy after login


回复讨论(解决方案)

先移植解密函数到 php

function hdth_normal_decode($in) {  $out = '';   $len = strlen($in);  for($i=0; $i<$len; $i+=2) {    $h = ord($in{$i}) - ord('c');    $l = ord($in{$i+1}) - ord('f');    $c = ($l << 4) + ($h & 0xf);    $out .= chr($c);  }  return $out;}
Copy after login
然后求其逆运算
function hdth_normal_encode($in) {  $out = '';  $len = strlen($in);  for($i=0; $i<$len; $i++) {    $c = ord($in{$i});    $l = ($c >> 4) + ord('f');    $h = ($c & 0xf) + ord('c');    $out .= chr($h) . chr($l);  }  return $out;}
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!