3v4l.org

run code in 300+ 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:  40
compiled vars:  !0 = $salt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   INIT_FCALL                                               'substr'
          1        INIT_FCALL                                               'base_convert'
          2        INIT_FCALL                                               'bin2hex'
          3        INIT_FCALL                                               'random_bytes'
          4        SEND_VAL                                                 6
          5        DO_ICALL                                         $1      
          6        SEND_VAR                                                 $1
          7        DO_ICALL                                         $2      
          8        SEND_VAR                                                 $2
          9        SEND_VAL                                                 16
         10        SEND_VAL                                                 36
         11        DO_ICALL                                         $3      
         12        SEND_VAR                                                 $3
         13        SEND_VAL                                                 1
         14        SEND_VAL                                                 8
         15        DO_ICALL                                         $4      
         16        ASSIGN                                                   !0, $4
   69    17        INIT_FCALL                                               'var_dump'
   70    18        INIT_FCALL                                               'crypt_apr1_md5'
         19        SEND_VAL                                                 'password'
         20        SEND_VAR                                                 !0
         21        DO_FCALL                                      0  $6      
         22        SEND_VAR                                                 $6
   71    23        INIT_FCALL                                               'crypt_apr1_md5'
         24        SEND_VAL                                                 'password'
         25        SEND_VAR                                                 !0
         26        DO_FCALL                                      0  $7      
         27        SEND_VAR                                                 $7
         28        DO_ICALL                                                 
   74    29        INIT_FCALL                                               'var_dump'
   75    30        INIT_FCALL                                               'crypt_apr1_md5'
         31        SEND_VAL                                                 'password'
         32        DO_FCALL                                      0  $9      
         33        SEND_VAR                                                 $9
   76    34        INIT_FCALL                                               'crypt_apr1_md5'
         35        SEND_VAL                                                 'password'
         36        DO_FCALL                                      0  $10     
         37        SEND_VAR                                                 $10
         38        DO_ICALL                                                 
   77    39      > RETURN                                                   1

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

End of function crypt_apr1_md5

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.63 ms | 1415 KiB | 39 Q