Des encryption and decryption algorithm-how can I get PHP code: 62837 << 16 Get the same results in Windows and Linux?

Source: Internet
Author: User
Tags gmp
Des encryption operations, found in Windows and Linux results are not the same, found that the CreateKey process has this operation, starting from here is not the same.

The network query was informed that an int overflow caused the correct under Windows. It is recommended to operate through the GMP extension, but no specific usage is found, please advise

Win results: 176881664
Lin Results: 759700962142060544

@eechen

Reply content:

Des encryption operations, found in Windows and Linux results are not the same, found that the CreateKey process has this operation, starting from here is not the same.

The network query was informed that an int overflow caused the correct under Windows. It is recommended to operate through the GMP extension, but no specific usage is found, please advise

Win results: 176881664
Lin Results: 759700962142060544

@eechen

Congratulations on falling into a big hole in PHP.

If a given number exceeds the range of integers, it will be interpreted as float. Similarly, float is returned if the result of the operation is outside the integer range.

This is the problem that has led to a variety of bizarre problems.

PHP does not support unsigned integers.

Reference PHP Original

However, you have this problem because the length of your two systems (PHP int type is long in the kernel) is inconsistent (because the number of system bits is not the same).
Therefore, if you want to work around this problem, you must manually process the int to uint.

$flag=$int&0x80000000;//取出符号位,判断是否是负数,溢出int范围,但没溢出uint范围时,符号位为1,即为负数if($flag){    $int ^= 0xffffffff;    $int += 1;}

BTW, the latest PHP7 fixes this problem, but PHP cannot shift a negative number.

Do not know where this code is from, the left and right to move the negative number of the code is done by the CPU, so it is completely dependent on the machine, and the system is not a big relationship, see if you can fix this code, or can only use other methods to replace the left and right to move negative numbers.

So starting from the PHP7, the displacement of a negative number will be directly error ...

  • 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.