Recently, the project needs to thank a simple PHP encryption and decryption function. If you have any shortcomings in the code, let us know.
Function encode_pass ($ Tex, $ key, $ type = "encode "){
$ Chrarr = array ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'h ', 'I', 'J', 'k', 'l', 'M', 'n', 'O', 'P', 'Q', 'R ', 'S ', 't', 'U', 'V', 'w', 'x', 'y', 'z ',
'A', 'B', 'C', 'D', 'E', 'E', 'F', 'G', 'h', 'I', 'J ', 'k', 'l', 'M', 'n', 'O', 'P', 'Q', 'R', 's','t ', 'U', 'V', 'w', 'x', 'y', 'z ',
'0', '1', '2', '3', '4', '5', '6', '7', '8 ', '9 ');
If ($ type = "decode "){
If (strlen ($ Tex) <14) return false;
$ Verity_str = substr ($ Tex, 0, 8 );
$ Tex = substr ($ Tex, 8 );
If ($ verity_str! = Substr (MD5 ($ Tex), 0, 8 )){
// Integrity Verification Failed
Return false;
}
}
$ Key_ B = $ type = "decode "? Substr ($ Tex, 0, 6): $ chrarr [rand () % 62]. $ chrarr [rand () % 62]. $ chrarr [rand () % 62]. $ chrarr [rand () % 62]. $ chrarr [rand () % 62]. $ chrarr [rand () % 62];
$ Rand_key = $ key_ B. $ key;
$ Rand_key = MD5 ($ rand_key );
$ Tex = $ type = "decode "? Base64_decode (substr ($ Tex, 6): $ Tex;
$ Texlen = strlen ($ Tex );
$ Reslutstr = "";
For ($ I = 0; $ I <$ texlen; $ I ++ ){
$ Reslutstr. = $ Tex {$ I} ^ $ rand_key {$ I % 32 };
}
If ($ type! = "Decode "){
$ Reslutstr = trim ($ key_ B .base64_encode ($ reslutstr), "= ");
$ Reslutstr = substr (MD5 ($ reslutstr), 0, 8). $ reslutstr;
}
Return $ reslutstr;
}
$ PSA = encode_pass ("phpcode", "taintainxousad ");
Echo $ PSA;
Echo encode_pass ($ PSA, "taintainxousad", 'decode ');