Des encryption and decryption algorithm-how can I make php code: 62837 <-16 get the same result in windows and linux?

Source: Internet
Author: User
Tags gmp
After performing the des encryption operation, we found that the results obtained in windows and linux are different. it is found that this operation exists in the createkey process and is different from here. The network query result is int overflow, which is correct in windows. We recommend that you use the gmp extension, but the details are not found... after performing the des encryption operation, we found that the results obtained in windows and linux are different. it is found that this operation exists in the createkey process and is different from here.

The network query result is int overflow, which is correct in windows. It is recommended to use gmp extension, but no specific usage is found. please advise

Result of win:-176881664
Result of lin:-759700962142060544.

@ Eechen

Reply content:

After performing the des encryption operation, we found that the results obtained in windows and linux are different. it is found that this operation exists in the createkey process and is different from here.

The network query result is int overflow, which is correct in windows. It is recommended to use gmp extension, but no specific usage is found. please advise

Result of win:-176881664
Result of lin:-759700962142060544.

@ Eechen

Congratulations! you fell into a big pitfall of php.

If a given number exceeds the integer range, it is interpreted as float. Similarly, if the execution result exceeds the integer range, float is returned.

This problem has caused various incredible problems.

PHP does not support unsigned integers.

Reference php original

However, this problem occurs because the length of the long type in both of your systems is inconsistent (because the number of digits in the system is different ).
Therefore, if you want to solve this problem, you must manually process int to uint.

$ Flag = $ int & 0x80000000; // Retrieve the symbol bit to determine whether it is a negative number. if the int range is exceeded but the uint range is not exceeded, the symbol bit is 1, that is, if ($ flag) {$ int ^ = 0 xffffffff; $ int + = 1 ;}

BTW, the latest php7 corrected this problem, but php cannot shift a negative number.

I don't know where this code comes from. the code with the left and right negative numbers is computed by the CPU, so it is completely dependent on the machine and has little to do with the system. check whether this code can be corrected, alternatively, you can only use other methods to replace the left-right negative shift.

So from php7, an error will be reported if a negative number is displaced...

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.