求php高手,看下这一段加密算法的原理
<br /> <br /> function sys_auth($str, $action = 'encode', $key = ''){<br /> $key = md5($key);<br /> $str = $action == 'encode' ? $str : base64_decode($str);<br /> <br /> <br /> $strlen = strlen($str);<br /> <br /> $keylen = strlen($key);<br /> <br /> $code = '';<br /> for($i = 0; $i < $strlen; $i++){<br /> $k = $i % $keylen;<br /> $code .= $str[$i] ^ $key[$k];<br /> }<br /> $code = $action == "decode" ? $code : base64_encode($code);<br /> return $code;<br /> }<br /> <br /> <br />
我将每句都echo 下的代码:
<br /> <br /> function sys_auth($str, $action = 'encode', $key = ''){<br /> $key = md5($key);<br /> echo '<br>$key:'.$key;<br /> $str = $action == 'encode' ? $str : base64_decode($str);<br /> <br /> echo '<br>加密方式的$str:'.$str;<br /> <br /> $strlen = strlen($str);<br /> echo '<br>$str长度'.$strlen;<br /> <br /> $keylen = strlen($key);<br /> echo '<br>$keylen长度'.$keylen;<br /> <br /> $code = '';<br /> for($i = 0; $i < $strlen; $i++){<br /> $k = $i % $keylen;<br /> echo "<br>第".$i."次循环的\$k的值是".$k;<br /> $code .= $str[$i] ^ $key[$k];<br /> echo "<br>第".$i.'次循环$k值是'.$k;<br /> echo "<br>第".$i.'次循环$str[$i]值是'.$str[$i];<br /> echo "<br>第".$i.'次循环$key[$k]值是'.$key[$k];<br /> echo "<br>第".$i."次循环的\$code的值是".$code."<br><br><br><br><br>";<br /> }<br /> $code = $action == "decode" ? $code : base64_encode($code);<br /> echo "<br>".$code;<br /> return $code;<br /> }<br /> <br /> <br /> 得到的结果是:<br /> [code=PHP]<br /> $key:c81e728d9d4c2f636f067f89cc14862c<br /> 加密方式的$str:123456<br /> $str长度6<br /> $keylen长度32<br /> 第0次循环的$k的值是0<br /> 第0次循环$k值是0<br /> 第0次循环$str[$i]值是1<br /> 第0次循环$key[$k]值是c<br /> 第0次循环的$code的值是R<br /> <br /> <br /> <br /> <br /> <br /> 第1次循环的$k的值是1<br /> 第1次循环$k值是1<br /> 第1次循环$str[$i]值是2<br /> 第1次循环$key[$k]值是8<br /> 第1次循环的$code的值是R <br /> <br /> <br /> <br /> <br /> <br /> 第2次循环的$k的值是2<br /> 第2次循环$k值是2<br /> 第2次循环$str[$i]值是3<br /> 第2次循环$key[$k]值是1<br /> 第2次循环的$code的值是R <br /> <br /> <br /> <br /> <br /> <br /> 第3次循环的$k的值是3<br /> 第3次循环$k值是3<br /> 第3次循环$str[$i]值是4<br /> 第3次循环$key[$k]值是e<br /> 第3次循环的$code的值是R Q<br /> <br /> <br /> <br /> <br /> <br /> 第4次循环的$k的值是4<br /> 第4次循环$k值是4<br /> 第4次循环$str[$i]值是5<br /> 第4次循环$key[$k]值是7<br /> 第4次循环的$code的值是R Q<br /> <br /> <br /> <br /> <br /> <br /> 第5次循环的$k的值是5<br /> 第5次循环$k值是5<br /> 第5次循环$str[$i]值是6<br /> 第5次循环$key[$k]值是2<br /> 第5次循环的$code的值是R Q<br /> <br /> <br /> <br /> <br /> <br /> UgoCUQIE<br /> 加密后:UgoCUQIE<br /> <br /> <br />
[/code]
现在的问题是:第0次循环$str[0]值是1,$key[0]值是c
我直接按照上面的 $str[0]^$key[0],(即1^0)却报错,怎么回事,另外 $str[0]^$key[0]不懂
------解决方案--------------------
手册,运算符

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


Hot AI Tools

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

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

Undress AI Tool
Undress images for free

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

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

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
