Home > php教程 > PHP源码 > 自定义对称 加密和解密

自定义对称 加密和解密

PHP中文网
Release: 2016-05-23 16:38:54
Original
1160 people have browsed it

代码

function selfEncode($str, $k) {
    $encoded = '';
    $len = strlen($str);
    $lk = strlen($k);
    for($i = 0; $i < $len; $i++) 
    {
        $mod = fmod($i, $lk);
        $encoded .= $str[$i. &#39;&#39;] ^ $k[$mod.&#39;&#39;];
    }
    $encoded = base64_encode($encoded);
    
    return $encoded;
}
function selfDecode($str, $k) {
    $str = base64_decode($str);
    $decoded = &#39;&#39;;
    $len = strlen($str);
    $lk = strlen($k);
    for($i = 0; $i < $len; $i++) 
    {
        $mod = fmod($i, $lk);
        $decoded .= $str[$i. &#39;&#39;] ^ $k[$mod.&#39;&#39;];
    }
    
    return $decoded;
}

// 注意: $str 和 $k 都是字符串类型
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template