php实现简单的对称加解密

public function simple_encode($string = '', $skey = 'tgmnvqufpg')
    {
        $strArr   = str_split(base64_encode($string));
        $strCount = count($strArr);
        foreach (str_split($skey) as $key => $value) {
            $key < $strCount && $strArr[$key] .= $value;
        }
        
        return str_replace(array('=', '+', '/'), array('O0O0O', 'o000o', 'oo00o'), join('', $strArr));
    }

    public function simple_decode($string = '', $skey = 'tgmnvqufpg')
    {
        $strArr   = str_split(str_replace(array('O0O0O', 'o000o', 'oo00o'), array('=', '+', '/'), $string), 2);
        $strCount = count($strArr);
        foreach (str_split($skey) as $key => $value) {
            $key <= $strCount && isset($strArr[$key]) && $strArr[$key][1] === $value && $strArr[$key] = $strArr[$key][0];
        }

        return base64_decode(join('', $strArr));
    }

 

posted @ 2020-04-08 11:50  pengcx  阅读(279)  评论(0编辑  收藏  举报