gpt4 book ai didi

PHP:如何创建加密字符串的算法

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:55:10 24 4
gpt4 key购买 nike

<分区>

我想创建一个有两种方式(加密和解密)的算法,我在网上搜索了好几天,想找到一种方法来创建一个算法,该算法使用每个字符的字节数。

例子:

$string = "Hello";
$Array =[
'H' => 3827,
'e' => 371,
'l' => 472,
'o' => 182
];
(Encrypt): $string->encrypt->result: "48Hsj4adj373Hdue73"
(Decrypt): "48Hsj4adj373Hdue73"->decrypt->result: "Hello"

//How would I do it?

我找到了一个解决方案:

class c
{
function a($k, $w){
if($w === 0){
return $k*13;
}elseif($w === 1){
$arr = explode(",", $k);
$string = "";
foreach($arr as $ke){
$var = (int)$ke/13;
$string = $string.chr($var);
}
if(empty($string)){return "Error";}return $string;
}
}
function e($str){
$c = str_split($str);
$string = "";
foreach($c as $key=>$k){
$ke = c::a(ord($k), 0);
$string = $string.(string)$ke.',';
}
$string = rtrim($string, ',');
return $string;
}
function d($str){
return c::a($str, 1);
}
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com