PHP 双密码本

<?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);

 

posted @ 2021-04-07 11:24  时间掉飞机  阅读(721)  评论(0编辑  收藏  举报