This example describes the encryption and decryption algorithm for PHP combined with MD5. Share to everyone for your reference, specific as follows:
<?php/* Created on 2016-9-30 */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);
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)) {$st
R. = 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; } $data = ' Cloud Habitat Community WWW.JB51.net ';
Encrypted information $data =iconv ("GBK", "Utf-8", $data); $key = ' www.jb51.net ';
Key $encrypt = Encrypt ($data, $key);
$decrypt = Decrypt ($encrypt, $key);
Echo $encrypt, "<br/>", $decrypt;?>
The results of the operation are as follows:
Trxmtm8sfb3dghtr2qeuyqoxzmpmn8mo
Cloud-dwelling community www.jb51.net
PS: About encryption and decryption interested friends can also refer to the site online tools:
Password Security online detection:
Http://tools.jb51.net/password/my_password_safe
High Strength Password Generator:
Http://tools.jb51.net/password/CreateStrongPassword
MD5 Online Encryption Tool:
Http://tools.jb51.net/password/CreateMD5Password
Thunderbolt, Express, Cyclone URL encryption/decryption tool:
Http://tools.jb51.net/password/urlrethunder
Online hashing/hashing algorithm encryption tool:
Http://tools.jb51.net/password/hash_encrypt
For more information on PHP related content readers can view the site topics: "PHP Encryption Method Summary", "PHP code and transcoding Operation Skills Summary", "PHP object-oriented Program Design Introductory Course", "PHP Mathematical Arithmetic Skills summary", "PHP Array" operation Skills Encyclopedia, " Summary of PHP string usage, PHP data structure and algorithm tutorial, PHP programming algorithm Summary, PHP Regular Expression usage summary, and PHP Common database operation Skills Summary
I hope this article will help you with the PHP program design.