Table of Contents
XOR string encryption method after base64 encryption
Home Backend Development PHP Tutorial Share a newly written PHP encryption and decryption function

Share a newly written PHP encryption and decryption function

Feb 09, 2017 am 09:43 AM
laravel linux mysql nginx php

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!


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1654
14
PHP Tutorial
1252
29
C# Tutorial
1225
24
Compare and contrast MySQL and MariaDB. Compare and contrast MySQL and MariaDB. Apr 26, 2025 am 12:08 AM

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

What database versions are compatible with the latest Laravel? What database versions are compatible with the latest Laravel? Apr 25, 2025 am 12:25 AM

The latest version of Laravel10 is compatible with MySQL 5.7 and above, PostgreSQL 9.6 and above, SQLite 3.8.8 and above, SQLServer 2017 and above. These versions are chosen because they support Laravel's ORM features, such as the JSON data type of MySQL5.7, which improves query and storage efficiency.

NGINX and Apache: Understanding the Key Differences NGINX and Apache: Understanding the Key Differences Apr 26, 2025 am 12:01 AM

NGINX and Apache each have their own advantages and disadvantages, and the choice should be based on specific needs. 1.NGINX is suitable for high concurrency scenarios because of its asynchronous non-blocking architecture. 2. Apache is suitable for low-concurrency scenarios that require complex configurations, because of its modular design.

Explain how to use sessions for user authentication. Explain how to use sessions for user authentication. Apr 26, 2025 am 12:04 AM

The session realizes user authentication through the server-side state management mechanism. 1) Session creation and generation of unique IDs, 2) IDs are passed through cookies, 3) Server stores and accesses session data through IDs, 4) User authentication and status management are realized, improving application security and user experience.

How to uninstall MySQL and clean residual files How to uninstall MySQL and clean residual files Apr 29, 2025 pm 04:03 PM

To safely and thoroughly uninstall MySQL and clean all residual files, follow the following steps: 1. Stop MySQL service; 2. Uninstall MySQL packages; 3. Clean configuration files and data directories; 4. Verify that the uninstallation is thorough.

An efficient way to batch insert data in MySQL An efficient way to batch insert data in MySQL Apr 29, 2025 pm 04:18 PM

Efficient methods for batch inserting data in MySQL include: 1. Using INSERTINTO...VALUES syntax, 2. Using LOADDATAINFILE command, 3. Using transaction processing, 4. Adjust batch size, 5. Disable indexing, 6. Using INSERTIGNORE or INSERT...ONDUPLICATEKEYUPDATE, these methods can significantly improve database operation efficiency.

H5: Key Improvements in HTML5 H5: Key Improvements in HTML5 Apr 28, 2025 am 12:26 AM

HTML5 brings five key improvements: 1. Semantic tags improve code clarity and SEO effects; 2. Multimedia support simplifies video and audio embedding; 3. Form enhancement simplifies verification; 4. Offline and local storage improves user experience; 5. Canvas and graphics functions enhance the visualization of web pages.

How to understand DMA operations in C? How to understand DMA operations in C? Apr 28, 2025 pm 10:09 PM

DMA in C refers to DirectMemoryAccess, a direct memory access technology, allowing hardware devices to directly transmit data to memory without CPU intervention. 1) DMA operation is highly dependent on hardware devices and drivers, and the implementation method varies from system to system. 2) Direct access to memory may bring security risks, and the correctness and security of the code must be ensured. 3) DMA can improve performance, but improper use may lead to degradation of system performance. Through practice and learning, we can master the skills of using DMA and maximize its effectiveness in scenarios such as high-speed data transmission and real-time signal processing.

See all articles