PHP custom encryption method

不言
Release: 2023-03-24 19:02:01
Original
2616 people have browsed it

This article mainly introduces PHP custom encryption method, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

Simple encoding function (corresponding to the php_decode function)

function php_encode($str) {  
    if ($str=='' && strlen($str)>128) return false;  
    for($i=0; $i<strlen ($str); $i++){  
        $c = ord($str[$i]);  
        if ($c>31 && $c <107) $c += 20 ;  
        if ($c>106 && $c <127) $c -= 75 ;  
        $word = chr($c);  
        $s .= $word;  
    }   
    return $s;   
}
Copy after login
  • #ord() function returns the ASCII value of the first character of a string.

  • chr() function returns the character from the specified ASCII value.

Simple decoding function (corresponding to php_encode function)

function php_decode($str){  
    if ($str==&#39;&#39; && strlen($str )>128) return false;  
    for($i=0; $i<strlen($str); $i++){  
        $c = ord($word);  
        if ( $c>106 && $c<127 ) $c = $c-20;  
        if ($c>31 && $c< 107) $c = $c+75 ;  
        $word = chr( $c);  
        $s .= $word ;  
    }   
    return $s;   
}
Copy after login

Simple encryption function (corresponding to php_decrypt function)

function php_encrypt($str){  
     $encrypt_key = &#39;abcdefghijklmnopqrstuvwxyz1234567890&#39;;  
     $decrypt_key = &#39;ngzqtcobmuhelkpdawxfyivrsj2468021359&#39;;  
     if(strlen($str) == 0) return  false;  
     for($i=0;  $i<strlen($str); $i++){  
         for($j=0; $j<strlen($encrypt_key); $j++){  
             if ($str[$i] == $encrypt_key[$j]){  
                 $enstr .=  $decrypt_key[$j];  
                 break;  
              }  
          }  
     }  
     return $enstr;  
}
Copy after login

Simple decryption function (corresponding to php_encrypt Function corresponding)

 function php_encrypt($str){  
     $encrypt_key = &#39;abcdefghijklmnopqrstuvwxyz1234567890&#39;;  
     $decrypt_key = &#39;ngzqtcobmuhelkpdawxfyivrsj2468021359&#39;;  
     if(strlen($str) == 0) return  false;  
     for($i=0;  $i<strlen($str); $i++){  
         for($j=0; $j<strlen($decrypt_key); $j++){  
             if ($str[$i] == $decrypt_key[$j]){  
                 $enstr .=  $encrypt_key[$j];  
                 break;  
              }  
          }  
     }  
     return $enstr;  
}
Copy after login

Related recommendations:

php custom two-dimensional array sorting

php custom two-dimensional array sorting function array


The above is the detailed content of PHP custom encryption method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!