Home > Backend Development > PHP Tutorial > 如何求解16进制字符串的验证

如何求解16进制字符串的验证

PHPz
Release: 2020-09-04 14:50:31
Original
2096 people have browsed it

求解16进制字符串的验证的方法:首先使用【hexdec($arr[$i]);】转成10进制相加;然后通过【base_convert((string)$sum,10,16);】转成16进制;最后使用【substr】方法进行求解即可。

如何求解16进制字符串的验证

如何求解16进制字符串的验证?

问题:

D0 44 00 05 00 09 03 02 00 00 00 00 27 0D
Copy after login

对方告诉后最后的那个27是校验值

算法是求和

求解一段16进制的字符串的验证

因为每个字节是8位,所以求和只要后8位,前面的不要

把27前面的数据相加,然后取后8位

方法:

<?php
$string = &#39;D0 44 00 05 00 09 03 02 00 00 00 00&#39;;
$arr = explode(&#39; &#39;,$string);
$sum = 0;
for($i=0;$i<$len;$i++){
    $sum+=hexdec($arr[$i]); //先转成10进制相加
}
$sum = base_convert((string)$sum,10,16); //再转成16进制 = 127
//取后面两位
echo substr($sum,-2); // = 27
Copy after login

更多相关知识,请访问PHP中文网

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template