3v4l.org

run code in 500+ PHP versions simultaneously
<?php /** * @param string $password * @param string|null $salt */ function crypt_apr1_md5($password, $salt = null) { if (!$salt) { $salt = substr(base_convert(bin2hex(random_bytes(6)), 16, 36), 1, 8); } $len = strlen($password); $text = $password . '$apr1$' . $salt; $bin = pack("H32", md5($password . $salt . $password)); for ($i = $len; $i > 0; $i -= 16) { $text .= substr($bin, 0, min(16, $i)); } for ($i = $len; $i > 0; $i >>= 1) { $text .= ($i & 1) ? chr(0) : $password[0]; } $bin = pack("H32", md5($text)); for ($i = 0; $i < 1000; $i++) { $new = ($i & 1) ? $password : $bin; if ($i % 3) { $new .= $salt; } if ($i % 7) { $new .= $password; } $new .= ($i & 1) ? $bin : $password; $bin = pack("H32", md5($new)); } $tmp = ''; for ($i = 0; $i < 5; $i++) { $k = $i + 6; $j = $i + 12; if ($j == 16) { $j = 5; } $tmp = $bin[$i] . $bin[$k] . $bin[$j] . $tmp; } $tmp = chr(0) . chr(0) . $bin[11] . $tmp; $tmp = strtr( strrev(substr(base64_encode($tmp), 2)), "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ); return "$" . "apr1" . "$" . $salt . "$" . $tmp; } $salt = substr(base_convert(bin2hex(random_bytes(6)), 16, 36), 1, 8); var_dump( crypt_apr1_md5('password', $salt), crypt_apr1_md5('password', $salt) ); var_dump( crypt_apr1_md5('password'), crypt_apr1_md5('password') );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/89YpT
function name:  (null)
number of ops:  37
compiled vars:  !0 = $salt
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   67     0  E >   INIT_FCALL                                                   'base_convert'
          1        INIT_FCALL                                                   'bin2hex'
          2        INIT_FCALL                                                   'random_bytes'
          3        SEND_VAL                                                     6
          4        DO_ICALL                                             $1      
          5        SEND_VAR                                                     $1
          6        DO_ICALL                                             $2      
          7        SEND_VAR                                                     $2
          8        SEND_VAL                                                     16
          9        SEND_VAL                                                     36
         10        DO_ICALL                                             $3      
         11        FRAMELESS_ICALL_3                substr              ~4      $3, 1
         12        OP_DATA                                                      8
         13        ASSIGN                                                       !0, ~4
   69    14        INIT_FCALL                                                   'var_dump'
   70    15        INIT_FCALL                                                   'crypt_apr1_md5'
         16        SEND_VAL                                                     'password'
         17        SEND_VAR                                                     !0
         18        DO_FCALL                                          0  $6      
         19        SEND_VAR                                                     $6
   71    20        INIT_FCALL                                                   'crypt_apr1_md5'
         21        SEND_VAL                                                     'password'
         22        SEND_VAR                                                     !0
         23        DO_FCALL                                          0  $7      
         24        SEND_VAR                                                     $7
   69    25        DO_ICALL                                                     
   74    26        INIT_FCALL                                                   'var_dump'
   75    27        INIT_FCALL                                                   'crypt_apr1_md5'
         28        SEND_VAL                                                     'password'
         29        DO_FCALL                                          0  $9      
         30        SEND_VAR                                                     $9
   76    31        INIT_FCALL                                                   'crypt_apr1_md5'
         32        SEND_VAL                                                     'password'
         33        DO_FCALL                                          0  $10     
         34        SEND_VAR                                                     $10
   74    35        DO_ICALL                                                     
   77    36      > RETURN                                                       1

Function crypt_apr1_md5:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 18
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 35
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 44
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
2 jumps found. (Code = 44) Position 1 = 93, Position 2 = 64
Branch analysis from position: 93
1 jumps found. (Code = 42) Position 1 = 111
Branch analysis from position: 111
2 jumps found. (Code = 44) Position 1 = 113, Position 2 = 96
Branch analysis from position: 113
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 96
2 jumps found. (Code = 43) Position 1 = 102, Position 2 = 103
Branch analysis from position: 102
2 jumps found. (Code = 44) Position 1 = 113, Position 2 = 96
Branch analysis from position: 113
Branch analysis from position: 96
Branch analysis from position: 103
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 68
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 69
Branch analysis from position: 69
2 jumps found. (Code = 43) Position 1 = 72, Position 2 = 73
Branch analysis from position: 72
2 jumps found. (Code = 43) Position 1 = 75, Position 2 = 76
Branch analysis from position: 75
2 jumps found. (Code = 43) Position 1 = 78, Position 2 = 80
Branch analysis from position: 78
1 jumps found. (Code = 42) Position 1 = 81
Branch analysis from position: 81
2 jumps found. (Code = 44) Position 1 = 93, Position 2 = 64
Branch analysis from position: 93
Branch analysis from position: 64
Branch analysis from position: 80
2 jumps found. (Code = 44) Position 1 = 93, Position 2 = 64
Branch analysis from position: 93
Branch analysis from position: 64
Branch analysis from position: 76
Branch analysis from position: 73
Branch analysis from position: 68
2 jumps found. (Code = 43) Position 1 = 72, Position 2 = 73
Branch analysis from position: 72
Branch analysis from position: 73
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 48
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 44
Branch analysis from position: 54
Branch analysis from position: 44
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 44
Branch analysis from position: 54
Branch analysis from position: 44
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 35
Branch analysis from position: 42
Branch analysis from position: 35
Branch analysis from position: 18
filename:       /in/89YpT
function name:  crypt_apr1_md5
number of ops:  132
compiled vars:  !0 = $password, !1 = $salt, !2 = $len, !3 = $text, !4 = $bin, !5 = $i, !6 = $new, !7 = $tmp, !8 = $k, !9 = $j
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   RECV                                                 !0      
          1        RECV_INIT                                            !1      null
   10     2        BOOL_NOT                                             ~10     !1
          3      > JMPZ                                                         ~10, ->18
   11     4    >   INIT_FCALL                                                   'base_convert'
          5        INIT_FCALL                                                   'bin2hex'
          6        INIT_FCALL                                                   'random_bytes'
          7        SEND_VAL                                                     6
          8        DO_ICALL                                             $11     
          9        SEND_VAR                                                     $11
         10        DO_ICALL                                             $12     
         11        SEND_VAR                                                     $12
         12        SEND_VAL                                                     16
         13        SEND_VAL                                                     36
         14        DO_ICALL                                             $13     
         15        FRAMELESS_ICALL_3                substr              ~14     $13, 1
         16        OP_DATA                                                      8
         17        ASSIGN                                                       !1, ~14
   13    18    >   STRLEN                                               ~16     !0
         19        ASSIGN                                                       !2, ~16
   15    20        CONCAT                                               ~18     !0, '%24apr1%24'
         21        CONCAT                                               ~19     ~18, !1
         22        ASSIGN                                                       !3, ~19
   17    23        INIT_FCALL                                                   'pack'
         24        SEND_VAL                                                     'H32'
         25        INIT_FCALL                                                   'md5'
         26        CONCAT                                               ~21     !0, !1
         27        CONCAT                                               ~22     ~21, !0
         28        SEND_VAL                                                     ~22
         29        DO_ICALL                                             $23     
         30        SEND_VAR                                                     $23
         31        DO_ICALL                                             $24     
         32        ASSIGN                                                       !4, $24
   19    33        ASSIGN                                                       !5, !2
         34      > JMP                                                          ->40
   20    35    >   FRAMELESS_ICALL_2                min                 ~27     16, !5
         36        FRAMELESS_ICALL_3                substr              ~28     !4, 0
         37        OP_DATA                                                      ~27
         38        ASSIGN_OP                                         8          !3, ~28
   19    39        ASSIGN_OP                                         2          !5, 16
         40    >   IS_SMALLER                                                   0, !5
         41      > JMPNZ                                                        ~31, ->35
   23    42    >   ASSIGN                                                       !5, !2
         43      > JMP                                                          ->52
   24    44    >   BW_AND                                               ~33     !5, 1
         45      > JMPZ                                                         ~33, ->48
         46    >   QM_ASSIGN                                            ~34     '%00'
         47      > JMP                                                          ->50
         48    >   FETCH_DIM_R                                          ~35     !0, 0
         49        QM_ASSIGN                                            ~34     ~35
         50    >   ASSIGN_OP                                         8          !3, ~34
   23    51        ASSIGN_OP                                         7          !5, 1
         52    >   IS_SMALLER                                                   0, !5
         53      > JMPNZ                                                        ~38, ->44
   27    54    >   INIT_FCALL                                                   'pack'
         55        SEND_VAL                                                     'H32'
         56        INIT_FCALL                                                   'md5'
         57        SEND_VAR                                                     !3
         58        DO_ICALL                                             $39     
         59        SEND_VAR                                                     $39
         60        DO_ICALL                                             $40     
         61        ASSIGN                                                       !4, $40
   29    62        ASSIGN                                                       !5, 0
         63      > JMP                                                          ->91
   30    64    >   BW_AND                                               ~43     !5, 1
         65      > JMPZ                                                         ~43, ->68
         66    >   QM_ASSIGN                                            ~44     !0
         67      > JMP                                                          ->69
         68    >   QM_ASSIGN                                            ~44     !4
         69    >   ASSIGN                                                       !6, ~44
   32    70        MOD                                                  ~46     !5, 3
         71      > JMPZ                                                         ~46, ->73
   33    72    >   ASSIGN_OP                                         8          !6, !1
   36    73    >   MOD                                                  ~48     !5, 7
         74      > JMPZ                                                         ~48, ->76
   37    75    >   ASSIGN_OP                                         8          !6, !0
   40    76    >   BW_AND                                               ~50     !5, 1
         77      > JMPZ                                                         ~50, ->80
         78    >   QM_ASSIGN                                            ~51     !4
         79      > JMP                                                          ->81
         80    >   QM_ASSIGN                                            ~51     !0
         81    >   ASSIGN_OP                                         8          !6, ~51
   41    82        INIT_FCALL                                                   'pack'
         83        SEND_VAL                                                     'H32'
         84        INIT_FCALL                                                   'md5'
         85        SEND_VAR                                                     !6
         86        DO_ICALL                                             $53     
         87        SEND_VAR                                                     $53
         88        DO_ICALL                                             $54     
         89        ASSIGN                                                       !4, $54
   29    90        PRE_INC                                                      !5
         91    >   IS_SMALLER                                                   !5, 1000
         92      > JMPNZ                                                        ~57, ->64
   44    93    >   ASSIGN                                                       !7, ''
   46    94        ASSIGN                                                       !5, 0
         95      > JMP                                                          ->111
   47    96    >   ADD                                                  ~60     !5, 6
         97        ASSIGN                                                       !8, ~60
   48    98        ADD                                                  ~62     !5, 12
         99        ASSIGN                                                       !9, ~62
   50   100        IS_EQUAL                                                     !9, 16
        101      > JMPZ                                                         ~64, ->103
   51   102    >   ASSIGN                                                       !9, 5
   54   103    >   FETCH_DIM_R                                          ~66     !4, !5
        104        FETCH_DIM_R                                          ~67     !4, !8
        105        CONCAT                                               ~68     ~66, ~67
        106        FETCH_DIM_R                                          ~69     !4, !9
        107        CONCAT                                               ~70     ~68, ~69
        108        CONCAT                                               ~71     ~70, !7
        109        ASSIGN                                                       !7, ~71
   46   110        PRE_INC                                                      !5
        111    >   IS_SMALLER                                                   !5, 5
        112      > JMPNZ                                                        ~74, ->96
   57   113    >   FETCH_DIM_R                                          ~75     !4, 11
        114        CONCAT                                               ~76     '%00%00', ~75
        115        CONCAT                                               ~77     ~76, !7
        116        ASSIGN                                                       !7, ~77
   59   117        INIT_FCALL                                                   'strrev'
        118        INIT_FCALL                                                   'base64_encode'
        119        SEND_VAR                                                     !7
        120        DO_ICALL                                             $79     
        121        FRAMELESS_ICALL_2                substr              ~80     $79, 2
        122        SEND_VAL                                                     ~80
        123        DO_ICALL                                             $81     
   58   124        FRAMELESS_ICALL_3                strtr               ~82     $81, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%2B%2F'
   61   125        OP_DATA                                                      '.%2F0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
   58   126        ASSIGN                                                       !7, ~82
   64   127        CONCAT                                               ~84     '%24apr1%24', !1
        128        CONCAT                                               ~85     ~84, '%24'
        129        CONCAT                                               ~86     ~85, !7
        130      > RETURN                                                       ~86
   65   131*     > RETURN                                                       null

End of function crypt_apr1_md5

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
168.84 ms | 2207 KiB | 25 Q