PHP custom encryption method

Simple encoding function (corresponding to 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;   
}  
  • The ord() function returns the ASCII value of the first character of a string.

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

Simple decoding function (corresponding to php_encode function)

function php_decode($str){  
    if ($str=='' && 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;   
}  

Simple encryption function (corresponding to php_decrypt function)

function php_encrypt($str){  
     $encrypt_key = 'abcdefghijklmnopqrstuvwxyz1234567890';  
     $decrypt_key = 'ngzqtcobmuhelkpdawxfyivrsj2468021359';  
     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;  
} 

Simple decryption function (corresponding to php_encrypt function)

 function php_encrypt($str){  
     $encrypt_key = 'abcdefghijklmnopqrstuvwxyz1234567890';  
     $decrypt_key = 'ngzqtcobmuhelkpdawxfyivrsj2468021359';  
     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;  
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324749772&siteId=291194637