


des encryption and decryption algorithm - How can I make php code: 62837
Jul 06, 2016 pm 01:52 PM
Perform the des encryption operation and find that the results obtained in windows and linux are different. It is found that this operation is included in the createkey process, and it is different from here on.
The network query revealed that it was caused by int overflow, which is correct under Windows. It is recommended to operate through the gmp extension, but I have not found the specific usage. Please give me some advice
win’s result: -176881664
lin’s result: -759700962142060544
@eechen
Reply content:
Perform the des encryption operation and find that the results obtained in windows and linux are different. It is found that this operation is included in the createkey process, and it is different from here on.
The network query revealed that it was caused by int overflow, which is correct under Windows. It is recommended to operate through the gmp extension, but I have not found the specific usage. Please give me some advice
win’s result: -176881664
lin’s result: -759700962142060544
@eechen
Congratulations on falling into a big pit of php.
If a given number exceeds the range of integer, it will be interpreted as float. Similarly, if the result of the operation exceeds the range of integer, float will also be returned.
It is this problem that leads to all kinds of weird problems.
PHP does not support unsigned integers.
Quote php original text
However, this problem occurs because the lengths of the long types of your two systems (the int type of PHP are both long types in the kernel) are inconsistent (because the number of bits in the systems is different).
So, if you want to solve this problem, you must manually process int to uint.
$flag=$int&0x80000000; //取出符號(hào)位,判斷是否是負(fù)數(shù),溢出int范圍,但沒溢出uint范圍時(shí),符號(hào)位為1,即為負(fù)數(shù) if($flag){ $int ^= 0xffffffff; $int += 1; }
BTW, the latest php7 fixes this problem, but a negative number cannot be shifted in php.
I don’t know where this code comes from. The code for shifting negative numbers left and right is performed by the CPU, so it completely relies on the machine and has little to do with the system. Let’s see if we can correct this code, or The only way is to use other methods instead of shifting negative numbers left and right.
So starting from php7, if the displacement is a negative number, an error will be reported directly...

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

TostaycurrentwithPHPdevelopmentsandbestpractices,followkeynewssourceslikePHP.netandPHPWeekly,engagewithcommunitiesonforumsandconferences,keeptoolingupdatedandgraduallyadoptnewfeatures,andreadorcontributetoopensourceprojects.First,followreliablesource

PHPbecamepopularforwebdevelopmentduetoitseaseoflearning,seamlessintegrationwithHTML,widespreadhostingsupport,andalargeecosystemincludingframeworkslikeLaravelandCMSplatformslikeWordPress.Itexcelsinhandlingformsubmissions,managingusersessions,interacti

TosettherighttimezoneinPHP,usedate_default_timezone_set()functionatthestartofyourscriptwithavalididentifiersuchas'America/New_York'.1.Usedate_default_timezone_set()beforeanydate/timefunctions.2.Alternatively,configurethephp.inifilebysettingdate.timez

TovalidateuserinputinPHP,usebuilt-invalidationfunctionslikefilter_var()andfilter_input(),applyregularexpressionsforcustomformatssuchasusernamesorphonenumbers,checkdatatypesfornumericvalueslikeageorprice,setlengthlimitsandtrimwhitespacetopreventlayout

ThePhpfunctionSerialize () andunserialize () AreusedtoconvertcomplexdaTastructdestoresintostoraSandaBackagain.1.Serialize () c OnvertsdatalikecarraysorobjectsraystringcontainingTypeandstructureinformation.2.unserialize () Reconstruct theoriginalatataprom

You can embed PHP code into HTML files, but make sure that the file has an extension of .php so that the server can parse it correctly. Use standard tags to wrap PHP code, insert dynamic content anywhere in HTML. In addition, you can switch PHP and HTML multiple times in the same file to realize dynamic functions such as conditional rendering. Be sure to pay attention to the server configuration and syntax correctness to avoid problems caused by short labels, quotation mark errors or omitted end labels.

The key to writing clean and easy-to-maintain PHP code lies in clear naming, following standards, reasonable structure, making good use of comments and testability. 1. Use clear variables, functions and class names, such as $userData and calculateTotalPrice(); 2. Follow the PSR-12 standard unified code style; 3. Split the code structure according to responsibilities, and organize it using MVC or Laravel-style catalogs; 4. Avoid noodles-style code and split the logic into small functions with a single responsibility; 5. Add comments at key points and write interface documents to clarify parameters, return values ??and exceptions; 6. Improve testability, adopt dependency injection, reduce global state and static methods. These practices improve code quality, collaboration efficiency and post-maintenance ease.

Yes,youcanrunSQLqueriesusingPHP,andtheprocessinvolveschoosingadatabaseextension,connectingtothedatabase,executingqueriessafely,andclosingconnectionswhendone.Todothis,firstchoosebetweenMySQLiorPDO,withPDObeingmoreflexibleduetosupportingmultipledatabas
