Share a newly written PHP encryption and decryption function

高洛峰
Release: 2023-03-05 15:44:01
Original
2323 people have browsed it

XOR string encryption method after base64 encryption

Encryption

function encode($str,$key)
{
    $res = base64_encode($str);
    $code = $res^$key;
    return $code;
}
Copy after login
Copy after login

Decryption

function decode($str,$key)
{
    return base64_decode($str^$key);
}
Copy after login
Copy after login

Full code example:

$str = '111021';
$key = 'APPYJJ-PHONE-LAZY';
function encode($str,$key)
{
    $res = base64_encode($str);
    $code = $res^$key;
    return $code;
}
$str = encode($str,$key);
print_r($str);
echo "<hr>";
function decode($str,$key)
{
    return base64_decode($str^$key);
}
print_r(decode($str,$key));
Copy after login
Copy after login
  • The whole program is very simple~ According to logical thinking, it should be difficult to crack, if others don’t know your secret key;

  • If you still feel unsafe. So I’m just going to throw some light here; I suggest you continue to use shift operations in the encryption and decryption process

//加密的时候;
$a = $str >> 4;
//解密的时候则相反
$a = $str << 4;
Copy after login
Copy after login

ok!~ At this point, the blogger continues to work! ~~

XOR string encryption method after base64 encryption

Encryption

function encode($str,$key)
{
    $res = base64_encode($str);
    $code = $res^$key;
    return $code;
}
Copy after login
Copy after login

Decryption

function decode($str,$key)
{
    return base64_decode($str^$key);
}
Copy after login
Copy after login

Complete code example:

$str = '111021';
$key = 'APPYJJ-PHONE-LAZY';
function encode($str,$key)
{
    $res = base64_encode($str);
    $code = $res^$key;
    return $code;
}
$str = encode($str,$key);
print_r($str);
echo "<hr>";
function decode($str,$key)
{
    return base64_decode($str^$key);
}
print_r(decode($str,$key));
Copy after login
Copy after login
  • The whole program is very simple ~ according to logical thinking, it should be difficult to crack, in others Without knowing your secret key;

  • If you still feel unsafe. So I’m going to throw some light here; I suggest you continue to use shift operations in the encryption and decryption process

//加密的时候;
$a = $str >> 4;
//解密的时候则相反
$a = $str << 4;
Copy after login
Copy after login

For more related articles about sharing a newly written PHP encryption and decryption function, please pay attention to PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!