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)

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

Docker on Linux: Containerization for Linux Systems Docker on Linux: Containerization for Linux Systems Apr 22, 2025 am 12:03 AM

Docker is important on Linux because Linux is its native platform that provides rich tools and community support. 1. Install Docker: Use sudoapt-getupdate and sudoapt-getinstalldocker-cedocker-ce-clicotainerd.io. 2. Create and manage containers: Use dockerrun commands, such as dockerrun-d--namemynginx-p80:80nginx. 3. Write Dockerfile: Optimize the image size and use multi-stage construction. 4. Optimization and debugging: Use dockerlogs and dockerex

Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

How does MySQL differ from Oracle? How does MySQL differ from Oracle? Apr 22, 2025 pm 05:57 PM

MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.

Laravel vs. Python (with Frameworks): A Comparative Analysis Laravel vs. Python (with Frameworks): A Comparative Analysis Apr 21, 2025 am 12:15 AM

Laravel is suitable for projects that teams are familiar with PHP and require rich features, while Python frameworks depend on project requirements. 1.Laravel provides elegant syntax and rich features, suitable for projects that require rapid development and flexibility. 2. Django is suitable for complex applications because of its "battery inclusion" concept. 3.Flask is suitable for fast prototypes and small projects, providing great flexibility.

CentOS: Security, Stability, and Performance CentOS: Security, Stability, and Performance Apr 21, 2025 am 12:11 AM

CentOS is the first choice for server and enterprise environments for its superior security, stability and performance. 1) Security provides forced access control through SELinux to improve system security. 2) Stability is supported by the LTS version for up to 10 years to ensure the stability of the system. 3) Performance significantly improves system response speed and resource utilization by optimizing kernel and system configuration.

Linux: A Deep Dive into Its Fundamental Parts Linux: A Deep Dive into Its Fundamental Parts Apr 21, 2025 am 12:03 AM

The core components of Linux include kernel, file system, shell, user and kernel space, device drivers, and performance optimization and best practices. 1) The kernel is the core of the system, managing hardware, memory and processes. 2) The file system organizes data and supports multiple types such as ext4, Btrfs and XFS. 3) Shell is the command center for users to interact with the system and supports scripting. 4) Separate user space from kernel space to ensure system stability. 5) The device driver connects the hardware to the operating system. 6) Performance optimization includes tuning system configuration and following best practices.

See all articles