自定义对称 加密和解密

2015-12-17 0 301
自定义对称 加密和解密
function selfEncode($str, $k) {
    $encoded = '';
    $len = strlen($str);
    $lk = strlen($k);
    for($i = 0; $i < $len; $i++) 
    {
        $mod = fmod($i, $lk);
        $encoded .= $str[$i. ''] ^ $k[$mod.''];
    }
    $encoded = base64_encode($encoded);
    
    return $encoded;
}
function selfDecode($str, $k) {
    $str = base64_decode($str);
    $decoded = '';
    $len = strlen($str);
    $lk = strlen($k);
    for($i = 0; $i < $len; $i++) 
    {
        $mod = fmod($i, $lk);
        $decoded .= $str[$i. ''] ^ $k[$mod.''];
    }
    
    return $decoded;
}

// 注意: $str 和 $k 都是字符串类型

遇见资源网 php 自定义对称 加密和解密 http://www.ox520.com/8089.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务