PHP Custom encryption function, decryption

Source: Internet
Author: User
Tags md5 strlen

Encryption is the process of converting some characters into another string, simply by locking the door and only you have the key open. As a programmer should have their own encryption methods, the current most popular encryption algorithm is MD5 () encryption method. But it is not safe to use the software that has been cracked on the site. The following is a simple introduction to the custom cryptographic functions.

The code is as follows

"/* Encryption * *

function Addcoder ($STR)

{

$yuan = ' aba!c1db#ef2@cg$h%id_3jkl^e:m}4n.o{&f*p) 5q (G-r[sh]6tuiv7w+jxy8z9k0 ';

$jia = ' Zay%0bx+1c$wdv^eu2-t3 (f{sr&g4q_ph5*on6i) m:l7. Jk]j8k}ih@gf9#ed!cb[a ';

if (strlen ($str) = = 0) return false;

for ($i = 0; $i <strlen ($STR); $i + +)

{

for ($j = 0; $j <strlen ($yuan); $j + +)

{

if ($str [$i]== $yuan [$j])

{

$results. = $jia [$j];

Break

}

}

}

return $results;

}


/* Decryption */

function Removecoder ($STR)

{

$yuan = ' aba!c1db#ef2@cg$h%id_3jkl^e:m}4n.o{&f*p) 5q (G-r[sh]6tuiv7w+jxy8z9k0 ';

$jia = ' Zay%0bx+1c$wdv^eu2-t3 (f{sr&g4q_ph5*on6i) m:l7. Jk]j8k}ih@gf9#ed!cb[a ';

If (strlen ($STR) ==0) return false;

for ($i = 0; $i < strlen ($STR); $i + +)

{

for ($j = 0; $j <strlen ($jia); $j + +)

{

if ($str [$i]== $jia [$j])

{

$results. = $yuan [$j];

Break

}

}

}

return $results;

}

$str = "Www.111cn.net";
echo "before encrypting:". $str. " <br > ";
$str 1= Addcoder ($STR);
echo "Encrypted:". $str 1. " <br > ";
$str 2= Removecoder ($str 1);
echo "After decryption:". $str 2. " <br > ";

Example two, using Md5+base64_encode for editing and processing.

  code is as follows &nbs P;

<?php 
//www.111cn.net
Function Passport_encrypt ($ TXT, $key) { 
Srand (Double) microtime () * 1000000)  
$encrypt _key = MD5 (rand (0, 32000));  
$ CTR = 0; 
$tmp = ';  
for ($i = 0; $i < strlen ($txt); $i + +) { 
$ctr = $ctr = = Strlen ($encrypt _ Key)? 0: $ctr;  
$tmp. = $encrypt _key[$ctr]. ( $txt [$i] ^ $encrypt _key[$ctr + +]);  

Return Base64_encode (Passport_key ($tmp, $key));  
}
Function Passport_decrypt ($txt, $key) { 
$txt = Passport_key (Base64_decode ($txt), $key);  
$tmp = ' ';  
for ($i = 0; $i < strlen ($txt); $i + +) { 
$md 5 = $txt [$i]; 
$tmp. = $txt [+ + $i] ^ $md 5;  ;

return $tmp  
}
Function Passport_key ($txt, $encrypt _key) {&NBsp
$encrypt _key = MD5 ($encrypt _key);  
$ctr = 0; 
$tmp = ';  
for ($i = 0; $i < strlen ($txt) ; $i + +) { 
$ctr = $ctr = = strlen ($encrypt _key)? 0: $ctr;  
$tmp. = $txt [$i] ^ $encrypt _key[$ctr ++]; 

return $tmp;  

?

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.