Home > Article > Backend Development > PHP custom encryption method
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
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; }
#ord() function returns the ASCII value of the first character of a string.
chr() function returns the character from the specified ASCII value.
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; }
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; }
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; }
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!