首页 > Web开发 > 详细

PHP 双密码本

时间:2021-04-07 15:24:24      阅读:20      评论:0      收藏:0      [点我收藏+]
<?php

/**
 * @Description 加密
 * @param $str
 * @return array
 */
function transform(string $str) : array
{
    $booksecret = ‘+-. _@0123456789:qwertyuiopasdfghjklzxcvbnmMNBVCXZLKJHGFDSAPOIUYTREWQ‘;
    $bookshuffle = str_shuffle($booksecret);
    $res = null;
    $strM = strlen($str);

    for($i = 0; $i < $strM; $i++){
        $postion = strpos($booksecret,$str[$i]);
        $res .= $bookshuffle[$postion];
    }
    $result[‘shuff‘] = $bookshuffle;
    $result[‘req‘]   = $res;
    return $result;
}
$res = transform(‘Modified by: I will never know what the next difficulty is‘);

/**
 * @Description 解密
 * @param $content
 * @return string
 */
function gettrans(array $content) : string
{
    $booksecret = ‘+-. _@0123456789:qwertyuiopasdfghjklzxcvbnmMNBVCXZLKJHGFDSAPOIUYTREWQ‘;
    $shuff = $content[‘shuff‘];
    $res = $content[‘req‘];
    $strM = strlen($res);

    $con = null;
    for($i = 0; $i < $strM; $i++)
    {
        $con .= $booksecret[strpos($shuff,$res[$i])];
    }
    return $con;
}
echo gettrans($res);

 

PHP 双密码本

原文:https://www.cnblogs.com/LF-place/p/14626939.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!