PHP combined with MD5 encryption and decryption algorithm example _php skills

Source: Internet
Author: User
Tags chr decrypt md5 md5 encryption ord php programming php regular expression strlen

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.