How to decrypt the exclusive or encrypted PHP Strings in other languages-Principle of the php string exclusive or operation

Source: Internet
Author: User
The ^ operator in the PHP language is often used for encryption operations, and the decryption can also be done directly using ^, but when communicating with other languages, other languages such as objective-c may not be able to parse PHP's ^, especially when php uses multiple strings such as abc ^ def, in other languages, there are few such operations that can be directly performed, and the calculation principle cannot be solved: a ^ B: a and B

The ^ operator in the PHP language is often used for encryption operations, and the decryption can also be done directly using ^, but when communicating with other languages, other languages such as objective-c may not be able to parse PHP's ^, especially when php uses multiple strings such as abc ^ def, in other languages, there are few such operations that can be directly performed, and the calculation principle cannot be solved: a ^ B: a and B

The ^ operator in the PHP language is often used for encryption operations, and the decryption can also be done directly using ^, but when communicating with other languages, other languages such as objective-c may not be able to parse PHP ^, especially when php uses multiple strings such as 'abc' ^ 'def, there are few other languages that can be directly computed and cannot be solved.
Computing Principle:
'A' ^ 'B ':
The ASCII values of a and B are 97 and 98, respectively, and the hexadecimal values are 11100001,1100010, respectively.
Then use the two operators to perform an exclusive or operation. The result is as follows: 11.
Then convert the binary number 11 to a string.
A garbled code is displayed in the calculation result of the windon command line.

Note: If you want to convert binary 11 to binary 11 in PHP, you need to use the bin2str function in Appendix 1. There are other methods to convert string to binary on the Internet, but some of them use different results here, note:

The above is a simple exclusive or operation of two single strings, which is also introduced on the Internet. However, no relevant information is found on the internet for the exclusive or operation of multiple strings, here I will give a general explanation of the principles of PHP. Other languages can decrypt PHP in the same way as the logic. ^

'Abc' ^ 'def ':
The ASCII values of a, B, and c are 1100011, 98, and 99 respectively. After the binary conversion, the ASCII values are 11100001, 1100010, and respectively.
The ASCII values of d, e, and f are 100,101,102, which are 1100100,1100101, and 1100110 respectively after the binary conversion.
Compare the differences or values of the ASCII codes of a, d, B, e, c, and f on the left: 101 111 101
Then splice the three binary to string pairs.

'Abc' ^ 'defgh ':
Some languages can also implement the above string exclusive or operation. When you see this, you will be stunned, because we can find that the number of characters on both sides is also exclusive or operation.
Php simply compares the length of the short string of the two by left alignment.

Author's personal website: https://www.riji.info <无>
function str2bin($str = ''){    $bin_arr = array();    $str_arr = preg_split('//u', $str, 0, PREG_SPLIT_NO_EMPTY);    foreach ($str_arr as $val) {        if (ord($val) > 127) {            $bin_arr[] = hex2bin(str_replace('%', '', urlencode($val)));        } else {            $bin_arr[] = decbin(ord($val));        }    }    return implode(' ', $bin_arr);} function bin2str($bin_str = ''){    $str = '';    $bin_str = explode(' ', $bin_str);    foreach ($bin_str as $val) {        if (bindec($val) < 127) {            $str .= chr(bindec($val));        } else {            $str .= urldecode('%' . implode('%', str_split(bin2hex($val), 2)));        }    }    return $str;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.