Home > Backend Development > PHP Tutorial > 16位md5压缩为8位字符串算法疑惑

16位md5压缩为8位字符串算法疑惑

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:06:55
Original
2990 people have browsed it

生成一个8位的随机字符串

<code>function make_coupon_card() {    
    $code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';    
    $rand = $code[rand(0,25)]    
        .strtoupper(dechex(date('m')))    
        .date('d').substr(time(),-5)    
        .substr(microtime(),2,5)    
        .sprintf('%02d',rand(0,99));    
    for(    
        $a = md5( $rand, true ),    
        $s = '0123456789ABCDEFGHIJKLMNOPQRSTUV',    
        $d = '',    
        $f = 0;    
        $f </code>
Copy after login
Copy after login

对于( $g ^ ord( $a[ $f + 8 ] ) ) - $g & 0x1F 的按位异或 减去本身 再进行的与运算,最终的范围是0-31之间,这个是如何确定的?

回复内容:

生成一个8位的随机字符串

<code>function make_coupon_card() {    
    $code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';    
    $rand = $code[rand(0,25)]    
        .strtoupper(dechex(date('m')))    
        .date('d').substr(time(),-5)    
        .substr(microtime(),2,5)    
        .sprintf('%02d',rand(0,99));    
    for(    
        $a = md5( $rand, true ),    
        $s = '0123456789ABCDEFGHIJKLMNOPQRSTUV',    
        $d = '',    
        $f = 0;    
        $f </code>
Copy after login
Copy after login

对于( $g ^ ord( $a[ $f + 8 ] ) ) - $g & 0x1F 的按位异或 减去本身 再进行的与运算,最终的范围是0-31之间,这个是如何确定的?

( $g ^ ord( $a[ $f + 8 ] ) ) - $g & 0x1F
简而言之有个关键点,运算符-的优先级要比&高。
所以整体来看应该是( ( $g ^ ord( $a[ $f + 8 ] ) ) - $g )0x1F进行与运算,
0x1F就是十进制的31,取与的结果范围就限定在了0 - 31之间。

Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template