php 实现RC4加密解密
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">RC4算法 RC4加密算法是大名鼎鼎的RSA三人组中的头号<span style="color: black;">名人</span>Ron Rivest在1987年设计的密钥长度可变的流加密算法簇。RC4算法是一种在电子信息<span style="color: black;">行业</span>加密的技术手段,用于<span style="color: black;">没</span>线通信网络,是一种电子<span style="color: black;">暗码</span>,<span style="color: black;">仅有</span>经过授权(缴纳相应<span style="color: black;">花费</span>)的用户<span style="color: black;">才可</span>享受该服务。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">RC4于1987年提出,是一种对<span style="color: black;">叫作</span>加密算法,<span style="color: black;">亦</span><span style="color: black;">便是</span>说<span style="color: black;">运用</span>的密钥为单钥(或<span style="color: black;">叫作</span>为私钥)。RC4不是对明文进行分组处理,而是字节流的方式依次加密明文中的每一个字节,解密的时候<span style="color: black;">亦</span>是依次对密文中的每一个字节进行解密。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">RC4算法的特点是算法简单,运行速度快,<span style="color: black;">况且</span>密钥长度是可变的,可变范围为1-256字节(8-2048比特),在如今技术支持的前提下,当密钥长度为128比特时,用暴力法搜索密钥<span style="color: black;">已然</span>不太可行,<span style="color: black;">因此</span><span style="color: black;">能够</span>预见RC4的密钥范围任然<span style="color: black;">能够</span>在今后相当长的时间里抵御暴力搜索密钥的攻击。<span style="color: black;">实质</span>上,如今<span style="color: black;">亦</span><span style="color: black;">无</span>找到<span style="color: black;">针对</span>128bit密钥长度的RC4加密算法的有效攻击<span style="color: black;">办法</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;">/* $pwd 秘钥;
$data 要加密的数据
*/
public function rc4($pwd, $data)
{
$cipher = ;
$key[] = "";
$box[] = "";
$pwd_length = strlen($pwd);
$data_length = strlen($data);
for ($i = 0; $i < 256; $i++) {
$key[$i] = ord($pwd[$i % $pwd_length]);
$box[$i] = $i;
}
for ($j = $i = 0; $i < 256; $i++) {
$j = ($j + $box[$i] + $key[$i]) % 256;
$tmp = $box[$i];
$box[$i] = $box[$j];
$box[$j] = $tmp;
}
for ($a = $j = $i = 0; $i < $data_length; $i++) {
$a = ($a + 1) % 256;
$j = ($j + $box[$a]) % 256;
$tmp = $box[$a];
$box[$a] = $box[$j];
$box[$j] = $tmp;
$k = $box[(($box[$a] + $box[$j]) % 256)];
$cipher .= chr(ord($data[$i]) ^ $k);
}
return $cipher;
}</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">解密的话重新调用一次该<span style="color: black;">办法</span><span style="color: black;">就可</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">以上内容<span style="color: black;">期盼</span><span style="color: black;">帮忙</span>到<span style="color: black;">大众</span>,<span style="color: black;">非常多</span>PHPer在进阶的时候总会遇到<span style="color: black;">有些</span>问题和瓶颈,业务代码写多了<span style="color: black;">无</span>方向感,不<span style="color: black;">晓得</span>该从那里入手去<span style="color: black;">提高</span>,对此我整理了<span style="color: black;">有些</span>资料,<span style="color: black;">包含</span>但不限于:分布式架构、高可扩展、高性能、高并发、服务器性能调优、TP6,laravel,YII2,Redis,Swoole、Swoft、Kafka、Mysql优化、shell脚本、Docker、微服务、Nginx等多个知识点高级进阶干货<span style="color: black;">必须</span>的可<span style="color: black;">以避免</span>费分享给<span style="color: black;">大众</span>,<span style="color: black;">必须</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><a style="color: black;">>>视频、面试文档免费获取" class="LinkCard new css-1vqsdx1" data-image="https://pic4.zhimg.com/v2-2686790c46d4e5db4d4b344c23a17517_ipico.jpg" data-image-width="</a>150" data-image-height="150" data-za-detail-view-id="172"><span style="color: black;"><span style="color: black;">PHP进阶架构师>>>视频、面试文档免费获取</span><span style="color: black;"><span style="color: black;"></span>docs.qq.com/doc/DUEZEWEN0cVZicVRW</span></span><span style="color: black;"><img src="https://pic4.zhimg.com/v2-2686790c46d4e5db4d4b344c23a17517_ipico.jpg" style="width: 50%; margin-bottom: 20px;"></span></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">或 者关注咱们下面的知乎专栏</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><a style="color: black;"><span style="color: black;"><span style="color: black;">PHP大神进阶</span><span style="color: black;"><span style="color: black;"></span>zhuanlan.zhihu</span></span></a>.com/sixstarPHP<span style="color: black;"><img src="https://pic2.zhimg.com/v2-98ed0acdcd86b9af33d979844466f249_ipico.jpg" style="width: 50%; margin-bottom: 20px;"></span></div>
<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">源自</span>:https://www.cnblogs.com/haoxuanchen2014/p/7783782.html</div>
系统提示我验证码错误1500次 \~゛, 我完全同意你的看法,期待我们能深入探讨这个问题。 谢谢、感谢、感恩、辛苦了、有你真好等。
页:
[1]