zoukankan      html  css  js  c++  java
  • 加密,解密方法

    加密,解密方法

    //加密函数
        function jiami($txt, $key = 'secure_key')
        {
            $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-=_";
            $nh = rand(0, 64);
            $ch = $chars [$nh];
            $mdKey = md5($key . $ch);
            $mdKey = substr($mdKey, $nh % 8, $nh % 8 + 7);
            $txt = base64_encode($txt);
            $tmp = '';
            $i = 0;
            $j = 0;
            $k = 0;
            for ($i = 0; $i < strlen($txt); $i++) {
                $k = $k == strlen($mdKey) ? 0 : $k;
                $j = ($nh + strpos($chars, $txt [$i]) + ord($mdKey [$k++])) % 64;
                $tmp .= $chars [$j];
            }
            return $ch . $tmp;
        }
    
        //解密函数
        function jiemi($txt, $key = 'secure_key')
        {
            $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-=_";
            $ch = $txt [0];
            $nh = strpos($chars, $ch);
            $mdKey = md5($key . $ch);
            $mdKey = substr($mdKey, $nh % 8, $nh % 8 + 7);
            $txt = substr($txt, 1);
            $tmp = '';
            $i = 0;
            $j = 0;
            $k = 0;
            for ($i = 0; $i < strlen($txt); $i++) {
                $k = $k == strlen($mdKey) ? 0 : $k;
                $j = strpos($chars, $txt [$i]) - $nh - ord($mdKey [$k++]);
                while ($j < 0)
                    $j += 64;
                $tmp .= $chars [$j];
            }
            return base64_decode($tmp);
        }
  • 相关阅读:
    contest9 CF295 div1 ooxx? ooox? oooo?
    The 8KB bug
    简单消息框架
    示例页面
    Unity3d中角色模型和角色名字保持相对位置
    Unityd外发光Shader Lab
    Unity3D判断当前所在平台
    Unity3D中的shader基础知识
    Sql Server 分区
    MVC 使用缓存
  • 原文地址:https://www.cnblogs.com/bluealine/p/11063025.html
Copyright © 2011-2022 走看看