php使用异或实现的加密解密实例
字符串的加密解密在数据的处理中应该是经常使用的,但MD5加密是不可逆的,所以自能自己动手写一个加密解密函数,思路很。网上看了几个用异或实现的思路,看懂后
若a=b ^ c;则b=a ^ c (^是异或的意思),php在处理异或的字符时先把字符转化为二进制的ascii值,对这些值进行异或,获取结果后在将ascii值转化为字符,原理说晚了直接贴实现的代码:
复制代码 代码如下:
echo '';
$str='世界,你好';
function jiami($str,$key){
$key=md5($key);
$k=md5(rand(0,100));//相当于动态密钥
$k=substr($k,0,3);
$tmp="";
for($i=0;$i
}
return base64_encode($k.$tmp);
}
function jiemi($str,$key){
$len=strlen($str);
$key=md5($key);
$str=base64_decode($str);
$str=substr($str,3,$len-3);
$tmp="";
for($i=0;$i
}
return $tmp;
}
$key='cc';
$jh=jiami($str, $key);
echo '加密前:'.$str.'
';
echo '加密后:'.$jh.'
';
echo '解密后:'.jiemi($jh, $key).'
';
有机会在完善下,本函数实现的是简单的加密解密 ,

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide
