Cryptographic decryption functions encapsulated in the Onethink
<?PHP/** * System Encryption Method * @param string $data strings to be encrypted * @param string $key encryption key * @param int $expire expiry time Unit seconds * @return String * @author mai fuel <[email protected]>*/functionThink_encrypt ($data,$key= ",$expire= 0) { $key=MD5(Empty($key) ? C (' Data_auth_key '):$key); $data=Base64_encode($data); $x= 0; $len=strlen($data); $l=strlen($key); $char= ' '; for($i= 0;$i<$len;$i++) { if($x==$l)$x= 0; $char.=substr($key,$x, 1); $x++; } $str=sprintf('%010d ',$expire?$expire+ Time(): 0); for($i= 0;$i<$len;$i++) { $str.=CHR(Ord(substr($data,$i, 1)) + (Ord(substr($char,$i, 1)))%256); } return Str_replace(Array(' + ', '/', ' = '),Array(‘-‘,‘_‘,‘‘),Base64_encode($str));}/** * System Decryption Method * @param string $data the strings to decrypt (must be a string encrypted by the Think_encrypt method) * @param string $key encryption Key * @return String * @ Author mai fuel <[email protected]>*/functionThink_decrypt ($data,$key= ' '){ $key=MD5(Empty($key) ? C (' Data_auth_key '):$key); $data=Str_replace(Array(‘-‘,‘_‘),Array(' + ', '/'),$data); $mod 4=strlen($data)% 4; if($mod 4) { $data.=substr(' = = = ',$mod 4); } $data=Base64_decode($data); $expire=substr($data, 0,10); $data=substr($data, 10); if($expire> 0 &&$expire< Time()) { return‘‘; } $x= 0; $len=strlen($data); $l=strlen($key); $char=$str= ' '; for($i= 0;$i<$len;$i++) { if($x==$l)$x= 0; $char.=substr($key,$x, 1); $x++; } for($i= 0;$i<$len;$i++) { if(Ord(substr($data,$i, 1)) <Ord(substr($char,$i, 1))) { $str.=CHR((Ord(substr($data,$i, 1)) + 256)-Ord(substr($char,$i, 1))); }Else{ $str.=CHR(Ord(substr($data,$i, 1))-Ord(substr($char,$i, 1))); } } return Base64_decode($str);}?>
Onethink Cryptographic decryption function