Php-simple symmetric encryption algorithm and conversion functions between strings and hexadecimal notation, php-hexadecimal notation
/**
* Encryption of simple symmetric encryption algorithms
* @ Param String $ string the String to be encrypted
* @ Param String $ skey encrypt EKY
* @ Return String
*/
Function encode ($ string = '', $ skey = 'textphp '){
$ Skey = str_split (base64_encode ($ skey ));
$ StrArr = str_split (base64_encode ($ string ));
$ StrCount = count ($ strArr );
Foreach ($ skey as $ key => $ value ){
$ Key <$ strCount & $ strArr [$ key]. = $ value;
}
Return str_replace ('=', '0o0o', join ('', $ strArr ));
}
/**
* Decryption of simple symmetric encryption algorithms
* @ Param String $ string the String to be decrypted
* @ Param String $ skey decryption KEY
* @ Return String
*/
Function decode ($ string = '', $ skey = 'textphp '){
$ Skey = str_split (base64_encode ($ skey ));
$ StrArr = str_split (str_replace ('0o0o', '=', $ string), 2 );
$ StrCount = count ($ strArr );
Foreach ($ skey as $ key => $ value ){
$ Key <$ strCount & $ strArr [$ key] [1] ===$ value & $ strArr [$ key] = $ strArr [$ key] [0];
}
Return base64_decode (join ('', $ strArr ));
}
// Convert string to hexadecimal
Function str2hex ($ str, $ encoded = 'gbk '){
$ Hex = '';
If ($ encoded = 'gbk '){
$ Str = mb_convert_encoding ($ str, 'gbk', 'utf-8 ');
}
For ($ I = 0, $ length = mb_strlen ($ str); $ I <$ length; $ I ++ ){
$ Hex. = dechex (ord ($ str {$ I }));
}
Return $ hex;
}
// Convert the string in hexadecimal notation
Function hex2str ($ hex, $ encoded = 'gbk '){
$ Str = '';
$ Arr = str_split ($ hex, 2 );
Foreach ($ arr as $ bit ){
$ Str. = chr (hexdec ($ bit ));
}
If ($ encoded = 'gbk '){
$ Str = mb_convert_encoding ($ str, 'utf-8', 'gbk ');
}
Return $ str;
}