3v4l.org

run code in 300+ PHP versions simultaneously
<?php class HashCracker { private $range = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; private $length = 32; private $cycles = 1000; public function runBenchmark($hash, $prefix = '') { foreach ($this->range as $key) { $match = $prefix . $key; $timers[$match] = microtime(true); for ($i = 0; $i < $this->cycles; $i += 1) { // this is where you bomb the server stupidStringComparison($hash, $match); } $timers[$match] = microtime(true) - $timers[$match]; } asort($timers); end($timers); $hit = key($timers); var_dump($hit); if (strlen($hit) >= $this->length) { return $hit; } return $this->runBenchmark($hash, $hit); } } function stupidStringComparison($str1, $str2) { for ($i = 0; $i < strlen($str2) && $i < strlen($str1); $i += 1) { if ($str1[$i] !== $str2[$i]) { return false; } usleep(10); // yes, I can't get something reliable with my box otherwise because of cpu spikes } // really stupid - ignore this part. Just made up to inflate times return strlen($str1) === strlen($str2); } $password = 'hello'; $hashed = md5($password); var_dump('Hash to match: ' . $hashed); $cracked = (new HashCracker())->runBenchmark($hashed); var_dump('Cracked hash: ' . $cracked); var_dump($cracked === $hashed ? 'Success!' : 'Fail :( Retry!');
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tc7XU
function name:  (null)
number of ops:  28
compiled vars:  !0 = $password, !1 = $hashed, !2 = $cracked
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   ASSIGN                                                   !0, 'hello'
   53     1        INIT_FCALL                                               'md5'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $4      
          4        ASSIGN                                                   !1, $4
   55     5        INIT_FCALL                                               'var_dump'
          6        CONCAT                                           ~6      'Hash+to+match%3A+', !1
          7        SEND_VAL                                                 ~6
          8        DO_ICALL                                                 
   57     9        NEW                                              $8      'HashCracker'
         10        DO_FCALL                                      0          
         11        INIT_METHOD_CALL                                         $8, 'runBenchmark'
         12        SEND_VAR_EX                                              !1
         13        DO_FCALL                                      0  $10     
         14        ASSIGN                                                   !2, $10
   59    15        INIT_FCALL                                               'var_dump'
         16        CONCAT                                           ~12     'Cracked+hash%3A+', !2
         17        SEND_VAL                                                 ~12
         18        DO_ICALL                                                 
   60    19        INIT_FCALL                                               'var_dump'
         20        IS_IDENTICAL                                             !2, !1
         21      > JMPZ                                                     ~14, ->24
         22    >   QM_ASSIGN                                        ~15     'Success%21'
         23      > JMP                                                      ->25
         24    >   QM_ASSIGN                                        ~15     'Fail+%3A%28+Retry%21'
         25    >   SEND_VAL                                                 ~15
         26        DO_ICALL                                                 
         27      > RETURN                                                   1

Function stupidstringcomparison:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 4
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
Branch analysis from position: 19
Branch analysis from position: 19
filename:       /in/Tc7XU
function name:  stupidStringComparison
number of ops:  25
compiled vars:  !0 = $str1, !1 = $str2, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   40     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->13
   41     4    >   FETCH_DIM_R                                      ~4      !0, !2
          5        FETCH_DIM_R                                      ~5      !1, !2
          6        IS_NOT_IDENTICAL                                         ~4, ~5
          7      > JMPZ                                                     ~6, ->9
   42     8    > > RETURN                                                   <false>
   45     9    >   INIT_FCALL                                               'usleep'
         10        SEND_VAL                                                 10
         11        DO_ICALL                                                 
   40    12        ASSIGN_OP                                     1          !2, 1
         13    >   STRLEN                                           ~9      !1
         14        IS_SMALLER                                       ~10     !2, ~9
         15      > JMPZ_EX                                          ~10     ~10, ->19
         16    >   STRLEN                                           ~11     !0
         17        IS_SMALLER                                       ~12     !2, ~11
         18        BOOL                                             ~10     ~12
         19    > > JMPNZ                                                    ~10, ->4
   49    20    >   STRLEN                                           ~13     !0
         21        STRLEN                                           ~14     !1
         22        IS_IDENTICAL                                     ~15     ~13, ~14
         23      > RETURN                                                   ~15
   50    24*     > RETURN                                                   null

End of function stupidstringcomparison

Class HashCracker:
Function runbenchmark:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 30
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 30
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 14
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 14
Branch analysis from position: 22
Branch analysis from position: 14
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 49
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/Tc7XU
function name:  runBenchmark
number of ops:  55
compiled vars:  !0 = $hash, !1 = $prefix, !2 = $key, !3 = $match, !4 = $timers, !5 = $i, !6 = $hit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      ''
   11     2        FETCH_OBJ_R                                      ~7      'range'
          3      > FE_RESET_R                                       $8      ~7, ->30
          4    > > FE_FETCH_R                                               $8, !2, ->30
   12     5    >   CONCAT                                           ~9      !1, !2
          6        ASSIGN                                                   !3, ~9
   13     7        INIT_FCALL                                               'microtime'
          8        SEND_VAL                                                 <true>
          9        DO_ICALL                                         $12     
         10        ASSIGN_DIM                                               !4, !3
         11        OP_DATA                                                  $12
   15    12        ASSIGN                                                   !5, 0
         13      > JMP                                                      ->19
   17    14    >   INIT_FCALL_BY_NAME                                       'stupidStringComparison'
         15        SEND_VAR_EX                                              !0
         16        SEND_VAR_EX                                              !3
         17        DO_FCALL                                      0          
   15    18        ASSIGN_OP                                     1          !5, 1
         19    >   FETCH_OBJ_R                                      ~16     'cycles'
         20        IS_SMALLER                                               !5, ~16
         21      > JMPNZ                                                    ~17, ->14
   20    22    >   INIT_FCALL                                               'microtime'
         23        SEND_VAL                                                 <true>
         24        DO_ICALL                                         $19     
         25        FETCH_DIM_R                                      ~20     !4, !3
         26        SUB                                              ~21     $19, ~20
         27        ASSIGN_DIM                                               !4, !3
         28        OP_DATA                                                  ~21
   11    29      > JMP                                                      ->4
         30    >   FE_FREE                                                  $8
   23    31        INIT_FCALL                                               'asort'
         32        SEND_REF                                                 !4
         33        DO_ICALL                                                 
   24    34        INIT_FCALL                                               'end'
         35        SEND_REF                                                 !4
         36        DO_ICALL                                                 
   26    37        INIT_FCALL                                               'key'
         38        SEND_VAR                                                 !4
         39        DO_ICALL                                         $24     
         40        ASSIGN                                                   !6, $24
   28    41        INIT_FCALL                                               'var_dump'
         42        SEND_VAR                                                 !6
         43        DO_ICALL                                                 
   30    44        STRLEN                                           ~27     !6
         45        FETCH_OBJ_R                                      ~28     'length'
         46        IS_SMALLER_OR_EQUAL                                      ~28, ~27
         47      > JMPZ                                                     ~29, ->49
   31    48    > > RETURN                                                   !6
   34    49    >   INIT_METHOD_CALL                                         'runBenchmark'
         50        SEND_VAR_EX                                              !0
         51        SEND_VAR_EX                                              !6
         52        DO_FCALL                                      0  $30     
         53      > RETURN                                                   $30
   35    54*     > RETURN                                                   null

End of function runbenchmark

End of class HashCracker.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.44 ms | 1396 KiB | 27 Q