<?php
$num = 20;
class Mybase64
{
private static $map = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", "]");
public static function encode($n)
{
if (!is_int($n)) return false;
$a = (int)floor($n / 64);
$b = $n % 64;
$s = $a ? self::encode($a) : '';
$s1 = self::$map[$b];
return ($s). $s1;
}
public static function decode($code)
{
// 写一个 解密 上面 加密的
$arr = str_split($code);
$key = [];
foreach ($arr as $v) {
$key[] = array_search($v,self::$map);
}
global $value;
$i = 0;
$count = count($key)-1;
if ($count == 0) {
return $key[0];
}
foreach ($key as $k => $val) {
$i++;
if (!$value) {
$num = $val * 64;
$value = $num + $key[++$k];
}elseif ($i <= $count) {
$num = $value * 64;
$value = $num + $key[++$k];
}
}
return $value;
}
public static function decodee($code){
$map = self::$map;
$map_f = array_flip($map);
$b = 0;
$long = strlen($code);
if($long>0){
$pow = pow(64,$long-1);
$new_code = substr($code,1);
$c = $map_f[$code[0]]*$pow;
$b = $c+self::decodee($new_code);
}
return $b;
}
}
echo 'summer方法';
echo '
';
b = num);
echo '要加密的数字:'.b;
echo '
';
a->decode(de;
echo '
';
if (de) {
echo "结果OK";
}else{
echo "错误";
}
echo '
';
echo '
';
echo 'kevin方法';
echo '
';
a->encode(num;
echo '
';
echo '密码:'.de = b);
echo '解密后:'.num==$de) {
echo "结果OK";
}else{
echo "错误";
}
网友评论