Php uses an exclusive encryption and decryption instance. If AB ^ c is used, ba ^ c (^ indicates an exclusive or exclusive character). When php processes an exclusive or character, it first converts the character to a binary ascii value, returns an ascii value if a = B ^ c. Then, B = a ^ c (^ indicates an exclusive or ), php converts a character to a binary ascii value when processing an exclusive or character, returns an exclusive or exclusive ascii value, the principle is described as follows:
The code is as follows:
Echo' ';
$ Str = 'World, hao ';
Function jiami ($ str, $ key ){
$ Key = md5 ($ key );
$ K = md5 (rand (0,100); // equivalent to a dynamic key
$ K = substr ($ k, 0, 3 );
$ Tmp = "";
For ($ I = 0; $ I
$ Tmp. = substr ($ str, $ I, 1) ^ substr ($ key, $ I, 1 );
}
Return base64_encode ($ k. $ tmp );
}
Function jiemi ($ str, $ key ){
$ Len = strlen ($ str );
$ Key = md5 ($ key );
$ Str = base64_decode ($ str );
$ Str = substr ($ str, 3, $ len-3 );
$ Tmp = "";
For ($ I = 0; $ I
$ Tmp. = substr ($ str, $ I, 1) ^ substr ($ key, $ I, 1 );
}
Return $ tmp;
}
$ Key = 'CC ';
$ Keys = jiami ($ str, $ key );
Echo 'Before encryption: '. $ str .'
';
Echo 'encrypted: '. $ encrypted .'
';
Echo 'decrypted: '. jiemi ($ decrypt, $ key ).'
';
With the opportunity to improve, this function implements simple encryption and decryption.
Then, B = a ^ c (^ indicates an exclusive or exclusive character). php converts the character into the binary ascii value when processing the exclusive or character, returns the ascii value after obtaining the result...