Encryption and decryption string function source code in PHP
Release: 2016-07-25 08:44:21
Original
1025 people have browsed it
PHP中加密解密字符串函数源代码:
-
- /**
- *Function: Encrypt string
- *Parameter 1: Content to be encrypted
- *Parameter 2: Key
- */
- function passport_encrypt($str,$key){ //加密函数
- srand((double)microtime() * 1000000);
- $encrypt_key=md5(rand(0, 32000));
- $ctr=0;
- $tmp='';
- for($i=0;$i $ctr=$ctr==strlen($encrypt_key)?0:$ctr;
- $tmp.=$encrypt_key[$ctr].($str[$i] ^ $encrypt_key[$ctr++]);
- }
- return base64_encode(passport_key($tmp,$key));
- }
- /**
- *Function: Decrypt string
- *Parameter 1: ciphertext to be decrypted
- *Parameter 2: Key
- */
- function passport_decrypt($str,$key){ //解密函数
- $str=passport_key(base64_decode($str),$key);
- $tmp='';
- for($i=0;$i $md5=$str[$i];
- $tmp.=$str[++$i] ^ $md5;
- }
- return $tmp;
- }
- /**
- *Auxiliary function
- */
- function passport_key($str,$encrypt_key){
- $encrypt_key=md5($encrypt_key);
- $ctr=0;
- $tmp='';
- for($i=0;$i $ctr=$ctr==strlen($encrypt_key)?0:$ctr;
- $tmp.=$str[$i] ^ $encrypt_key[$ctr++];
- }
- return $tmp;
- }
- $str='作者:uphtm.com;
- $key='uphtm.com';
- $encrypt=passport_encrypt($str,$key);
- $decrypt=passport_decrypt($encrypt,$key);
- echo '原文:',$str."
";
- echo '密文:',$encrypt."
";
- echo '译文:',$decrypt."
";
- ?>
-
复制代码
|
加密解密, PHP
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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31