Home Backend Development PHP Tutorial 两组容易的PHP解密解密代码

两组容易的PHP解密解密代码

Jun 13, 2016 am 11:39 AM
data key string

两组简单的PHP解密解密代码
http://www.phper.org.cn/?post=133
加密算法如下:

function encrypt($data, $key){	$key	=	md5($key);    $x		=	0;    $len	=	strlen($data);    $l		=	strlen($key);    for ($i = 0; $i < $len; $i++)    {        if ($x == $l)         {        	$x = 0;        }        $char .= $key{$x};        $x++;    }    for ($i = 0; $i < $len; $i++)    {        $str .= chr(ord($data{$i}) + (ord($char{$i})) % 256);    }    return base64_encode($str);}
Copy after login


解密算法如下:
function decrypt($data, $key){	$key = md5($key);    $x = 0;    $data = base64_decode($data);    $len = strlen($data);    $l = strlen($key);    for ($i = 0; $i < $len; $i++)    {        if ($x == $l)         {        	$x = 0;        }        $char .= substr($key, $x, 1);        $x++;    }    for ($i = 0; $i < $len; $i++)    {        if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1)))        {            $str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));        }        else        {            $str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));        }    }    return $str;}
Copy after login

使用:
$data = 'PHP加密解密算法';		// 被加密信息$key = '123';					// 密钥$encrypt = encrypt($data, $key);$decrypt = decrypt($encrypt, $key);echo $encrypt, "\n", $decrypt;
Copy after login





http://www.thinkphp.cn/code/282.html
/** * 通用加密 * @param String $string 需要加密的字串 * @param String $skey 加密EKY * @author Anyon Zou <[email&#160;protected]> * @date 2013-08-13 19:30 * @return String */ function enCode($string = '', $skey = 'echounion') {    $skey = array_reverse(str_split($skey));    $strArr = str_split(base64_encode($string));    $strCount = count($strArr);    foreach ($skey as $key => $value) {        $key < $strCount && $strArr[$key].=$value;    }    return str_replace('=', 'O0O0O', join('', $strArr)); } /** * 通用解密 * @param String $string 需要解密的字串 * @param String $skey 解密KEY * @return String * @author Anyon Zou <[email&#160;protected]> * @date 2013-08-13 19:30 */ function deCode($string = '', $skey = 'echounion') {    $skey = array_reverse(str_split($skey));    $strArr = str_split(str_replace('O0O0O', '=', $string), 2);    $strCount = count($strArr);    foreach ($skey as $key => $value) {        $key < $strCount && $strArr[$key] = rtrim($strArr[$key], $value);    }    return base64_decode(join('', $strArr)); }
Copy after login

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

Convert basic data types to strings using Java's String.valueOf() function Convert basic data types to strings using Java's String.valueOf() function Jul 24, 2023 pm 07:55 PM

Convert basic data types to strings using Java's String.valueOf() function In Java development, when we need to convert basic data types to strings, a common method is to use the valueOf() function of the String class. This function can accept parameters of basic data types and return the corresponding string representation. In this article, we will explore how to use the String.valueOf() function for basic data type conversions and provide some code examples to

What does the identity attribute in SQL mean? What does the identity attribute in SQL mean? Feb 19, 2024 am 11:24 AM

What is Identity in SQL? Specific code examples are needed. In SQL, Identity is a special data type used to generate auto-incrementing numbers. It is often used to uniquely identify each row of data in a table. The Identity column is often used in conjunction with the primary key column to ensure that each record has a unique identifier. This article will detail how to use Identity and some practical code examples. The basic way to use Identity is to use Identit when creating a table.

How to convert char array to string How to convert char array to string Jun 09, 2023 am 10:04 AM

Method of converting char array to string: It can be achieved by assignment. Use {char a[]=" abc d\0efg ";string s=a;} syntax to let the char array directly assign a value to string, and execute the code to complete the conversion.

How SpringBoot monitors redis Key change events How SpringBoot monitors redis Key change events May 26, 2023 pm 01:55 PM

1. Function Overview Keyspace notification allows clients to receive events that modify Rediskey changes in some way by subscribing to channels or patterns. All commands that modify key keys. All keys that received the LPUSHkeyvalue[value…] command. All expired keys in the db database. Events are distributed through Redis's subscription and publishing functions (pub/sub), so all clients that support subscription and publishing functions can directly use the keyspace notification function without any modifications. Because the current subscription and publishing functions of Redis adopt a fireandforget strategy, if your program

Use Java's String.replace() function to replace characters (strings) in a string Use Java's String.replace() function to replace characters (strings) in a string Jul 25, 2023 pm 05:16 PM

Replace characters (strings) in a string using Java's String.replace() function In Java, strings are immutable objects, which means that once a string object is created, its value cannot be modified. However, you may encounter situations where you need to replace certain characters or strings in a string. At this time, we can use the replace() method in Java's String class to implement string replacement. The replace() method of String class has two types:

Unpatchable Yubico two-factor authentication key vulnerability breaks the security of most Yubikey 5, Security Key, and YubiHSM 2FA devices Unpatchable Yubico two-factor authentication key vulnerability breaks the security of most Yubikey 5, Security Key, and YubiHSM 2FA devices Sep 04, 2024 pm 06:32 PM

An unpatchable Yubico two-factor authentication key vulnerability has broken the security of most Yubikey 5, Security Key, and YubiHSM 2FA devices. The Feitian A22 JavaCard and other devices using Infineon SLB96xx series TPMs are also vulnerable.All

2w words detailed explanation String, yyds 2w words detailed explanation String, yyds Aug 24, 2023 pm 03:56 PM

Hello everyone, today I will share with you the basic knowledge of Java: String. Needless to say the importance of the String class, it can be said to be the most used class in our back-end development, so it is necessary to talk about it.

How to solve the problem of batch deletion of key values ​​in redis How to solve the problem of batch deletion of key values ​​in redis May 31, 2023 am 08:59 AM

Problems encountered: During the development process, you will encounter keys that need to be deleted in batches according to certain rules, such as login_logID (ID is a variable). Now you need to delete data such as "login_log*", but redis itself only has batch query. Command keys for class key values, but there is no command for batch deletion of a certain class. Solution: Query first, then delete, use xargs to pass parameters (xargs can convert pipe or standard input (stdin) data into command line parameters), execute the query statement first, and then remove the queried key value and the original del parameters. delete. redis-cliKEYSkey* (search condition)|xargsr

See all articles