这段代码不是挺复杂,其实如果你细看是可以看得到discuz中的authcode的影子的。如果你有兴趣,你可以看看:
源代码来自:http://blog.csdn.net/long892230/article/details/7562613
- /*加密函数内部调用函数*/
- function keyED($txt,$encrypt_key) {
- $encrypt_key = md5($encrypt_key);
- $ctr=0;
- $tmp = "";
- for ($i=0;$i<strlen($txt);$i++) {
- if ($ctr==strlen($encrypt_key)) $ctr=0;
- $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
- $ctr++;
- }
- return $tmp;
- }
- /*发送邮件中连接地址的加密函数*/
- function inner_DYEncrypt( $encryptstr ){
- return urlencode(inner_DYEncrypt_subfun($encryptstr));
- }
- function inner_DYEncrypt_subfun($encryptstr){
- srand((double)microtime()*1000000);
- $encrypt_key = md5(rand(0,32000));
- $ctr=0; $tmpstr = "";
- for ($i=0;$i<strlen($encryptstr);$i++){
- if ($ctr==strlen($encrypt_key)) $ctr=0;
- $tmpstr.= substr($encrypt_key,$ctr,1) .
- (substr($encryptstr,$i,1) ^ substr($encrypt_key,$ctr,1));
- $ctr++;
- }
- $returninfo = base64_encode(keyED($tmpstr,ENCRYPTKEY));
- if (strrpos($returninfo,"/") or strrpos($returninfo,'') or strrpos($returninfo,'+'))
- return inner_DYEncrypt_subfun( $encryptstr );
- return $returninfo;
- }
- /*发送邮件中连接地址的解密函数*/
- function inner_DYDecrypt( $decryptstr ){
- $decryptstr = urldecode($decryptstr);
- $decryptstr = keyED(base64_decode($decryptstr),ENCRYPTKEY);
- $tmpstr = "";
- for ($i=0;$i<strlen($decryptstr);$i++){
- $md5 = substr($decryptstr,$i,1);
- $i++;
- $tmpstr.= (substr($decryptstr,$i,1) ^ $md5);
- }
- return $tmpstr;
- }
- /*演示*/
- $key = "rdid=5135"; //待加密的字符串
- echo "待加密的字符串:".$key."";
- $key = inner_DYEncrypt($key);
- echo "加密后的字符串:".$key."";
- echo "解密后的字符串:".inner_DYDecrypt($key);
- ?>
发完这个贴子的时候突然发现。我好久没有写博客了。倒不是不坚持,而是发现我实在没有什么东西好写了。一直吃老本,还能写什么?