bnbweb/includes/lib_code.php

48 lines
942 B
PHP
Raw Normal View History

2022-11-14 17:31:15 +00:00
<?php
if (!defined('IN_ECS'))
{
die('Hacking attempt');
}
/**
* 加密函数
* @param string $str 加密前的字符串
* @param string $key 密钥
* @return string 加密后的字符串
*/
function encrypt($str, $key = AUTH_KEY)
{
$coded = '';
$keylength = strlen($key);
for ($i = 0, $count = strlen($str); $i < $count; $i += $keylength)
{
$coded .= substr($str, $i, $keylength) ^ $key;
}
return str_replace('=', '', base64_encode($coded));
}
/**
* 解密函数
* @param string $str 加密后的字符串
* @param string $key 密钥
* @return string 加密前的字符串
*/
function decrypt($str, $key = AUTH_KEY)
{
$coded = '';
$keylength = strlen($key);
$str = base64_decode($str);
for ($i = 0, $count = strlen($str); $i < $count; $i += $keylength)
{
$coded .= substr($str, $i, $keylength) ^ $key;
}
return $coded;
}
2022-11-14 15:49:28 +00:00
?>