Two groups of easy PHP decryption and decryption code

Source: Internet
Author: User
Two groups of simple PHP decryption and decryption code
http://www.phper.org.cn/?post=133
The encryption algorithm is as follows:
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}))%);    }    Return Base64_encode ($STR);}


The decryption algorithm is as follows:
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 ($data, $i, 1) + substr)-Ord (substr ($char, $i, 1)));        }        else        {            $str. = Chr (Ord (substr ($data, $i, 1))-Ord (substr ($char, $i, 1)));        }    }    return $STR;}

Use:
$data = ' PHP encryption and decryption algorithm ';//encrypted information $key = ' 123 ';//Key $encrypt = Encrypt ($data, $key); $decrypt = Decrypt ($encrypt, $key); Echo $enc Rypt, "\ n", $decrypt;





Http://www.thinkphp.cn/code/282.html
/** * Universal Encryption * @param string $string strings that need to be encrypted * @param string $skey encryption Eky * @author Anyon Zou
 
  * @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)); }/** * Universal decryption * @param string $string The string to decrypt * @param string $skey Decrypt key * @return String * @author Anyon Zou
  
   
    * @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)); }

   
  
 

  • 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.