zoukankan      html  css  js  c++  java
  • PHP Token(令牌)设计应用

    转自:http://my.oschina.net/u/912810/blog/358973

    <?php  
    class GEncrypt {  
        protected static 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;     
        } 
    
        public static function encrypt($txt,$key){     
            //$encrypt_key = md5(rand(0,32000));  
            $encrypt_key = md5(((float) date("YmdHis") + rand(10000000000000000,99999999999999999)).rand(100000,999999));  
            $ctr=0;     
            $tmp = "";     
            for ($i=0;$i<strlen($txt);$i++){  
                if ($ctr==strlen($encrypt_key)) $ctr=0;     
                $tmp.= substr($encrypt_key,$ctr,1) . (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));     
                $ctr++;     
            }     
            return base64_encode(self::keyED($tmp,$key));  
        } 
    
        public static function decrypt($txt,$key){  
            $txt = self::keyED( base64_decode($txt),$key);     
            $tmp = "";  
            for ($i=0;$i<strlen($txt);$i++){     
                $md5 = substr($txt,$i,1);     
                $i++;     
                $tmp.= (substr($txt,$i,1) ^ $md5);     
            }  
            return $tmp;  
        }      
    }  
    ?> 

    完毕。

  • 相关阅读:
    poj 2002 Squares 几何二分 || 哈希
    hdu 1969 Pie
    hdu 4004 The Frog's Games 二分
    hdu 4190 Distributing Ballot Boxes 二分
    hdu 2141 Can you find it? 二分
    Codeforces Round #259 (Div. 2)
    并查集
    bfs
    二维树状数组
    一维树状数组
  • 原文地址:https://www.cnblogs.com/zl0372/p/php_token.html
Copyright © 2011-2022 走看看