php加密解密小算法

来源:互联网 发布:手机游戏源码论坛 编辑:程序博客网 时间:2024/06/01 21:27
/**
    * 字符串加密、解密函数
    *
    *
    * @param   string  $txt        字符串
    * @param   string  $operation  ENCODE为加密,DECODE为解密,可选参数,默认为ENCODE,
    * @param   string  $key        密钥:数字、字母、下划线
    * @return  string
    */
    function sys_auth($txt, $operation = 'ENCODE', $key = '')
    {
        $key = $key ? $key : "hehe";
        $txt = $operation == 'ENCODE' ? ( string ) $txt : base64_decode($txt);
        $len = strlen($key);
        $code = '';
        for ($i = 0; $i < strlen($txt); $i ++)
        {
             $k = $i % $len;
             $code .= $txt [$i] ^ $key [$k];
        }
        $code = $operation == 'DECODE' ? $code : base64_encode($code);
        return $code;
    }
0 0
原创粉丝点击