3v4l.org

run code in 500+ PHP versions simultaneously
<?php define('SECRET', 'tostersecretcode2015'); /** * Создаёт серийный номер с заданной проверочной частью. * * @param string $check Часть серийного номера, используемая для проверки. * * @return bool */ function sernum ($check = null) { $template = 'XXX99-XXX99-99XXX-99XXX'; $parts = explode('-', $template, 2); if (!isset($check)) { $check = ''; for ($i = 0; $i < strlen($parts[0]); $i++) { switch ($parts[0][$i]) { case 'X': $check .= chr(rand(65, 90)); break; case '9': $check .= strval(rand(0,9)); break; } } } $sernum = $check . '-'; $hash = hash('sha256', $check . SECRET); for ($i = 0; $i < strlen($parts[1]); $i++) { switch ($parts[1][$i]) { case 'X': $sernum .= chr(65 + ord($hash[$i]) % 26); break; case '9': $sernum .= strval(ord($hash[$i]) % 10); break; case '-': $sernum .= '-'; break; } } return $sernum; } /** * Проверяет серийный номер. * * @return bool */ function check_sernum ($sernum) { $parts = explode('-', $sernum, 2); return (sernum($parts[0]) === $sernum); } echo '<pre>Десять случайных номеров:<br>' . PHP_EOL; for ($i = 0; $i < 10; $i++) echo sernum() . '<br/>' . PHP_EOL; if (check_sernum('XCC58-AYA68-75ZUU-19TDZ')) { echo 'Номер XCC58-AYA68-75ZUU-19TDZ прошёл проверку<br>' . PHP_EOL; } if (!check_sernum('ESJ18-TBZ25-42XDX-38XWY')) { echo 'Номер ESJ18-TBZ25-42XDX-38XWY не прошёл проверку<br>' . PHP_EOL; }
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 = 44) Position 1 = 15, Position 2 = 7
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 26
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 20
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 7
Branch analysis from position: 15
Branch analysis from position: 7
filename:       /in/LHe5q
function name:  (null)
number of ops:  27
compiled vars:  !0 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                                   'define'
          1        SEND_VAL                                                     'SECRET'
          2        SEND_VAL                                                     'tostersecretcode2015'
          3        DO_ICALL                                                     
   53     4        ECHO                                                         '%3Cpre%3E%D0%94%D0%B5%D1%81%D1%8F%D1%82%D1%8C+%D1%81%D0%BB%D1%83%D1%87%D0%B0%D0%B9%D0%BD%D1%8B%D1%85+%D0%BD%D0%BE%D0%BC%D0%B5%D1%80%D0%BE%D0%B2%3A%3Cbr%3E%0A'
   54     5        ASSIGN                                                       !0, 0
          6      > JMP                                                          ->13
   55     7    >   INIT_FCALL                                                   'sernum'
          8        DO_FCALL                                          0  $3      
          9        CONCAT                                               ~4      $3, '%3Cbr%2F%3E'
         10        CONCAT                                               ~5      ~4, '%0A'
         11        ECHO                                                         ~5
   54    12        PRE_INC                                                      !0
         13    >   IS_SMALLER                                                   !0, 10
         14      > JMPNZ                                                        ~7, ->7
   57    15    >   INIT_FCALL                                                   'check_sernum'
         16        SEND_VAL                                                     'XCC58-AYA68-75ZUU-19TDZ'
         17        DO_FCALL                                          0  $8      
         18      > JMPZ                                                         $8, ->20
   58    19    >   ECHO                                                         '%D0%9D%D0%BE%D0%BC%D0%B5%D1%80+XCC58-AYA68-75ZUU-19TDZ+%D0%BF%D1%80%D0%BE%D1%88%D1%91%D0%BB+%D0%BF%D1%80%D0%BE%D0%B2%D0%B5%D1%80%D0%BA%D1%83%3Cbr%3E%0A'
   61    20    >   INIT_FCALL                                                   'check_sernum'
         21        SEND_VAL                                                     'ESJ18-TBZ25-42XDX-38XWY'
         22        DO_FCALL                                          0  $9      
         23        BOOL_NOT                                             ~10     $9
         24      > JMPZ                                                         ~10, ->26
   62    25    >   ECHO                                                         '%D0%9D%D0%BE%D0%BC%D0%B5%D1%80+ESJ18-TBZ25-42XDX-38XWY+%D0%BD%D0%B5+%D0%BF%D1%80%D0%BE%D1%88%D1%91%D0%BB+%D0%BF%D1%80%D0%BE%D0%B2%D0%B5%D1%80%D0%BA%D1%83%3Cbr%3E%0A'
   63    26    > > RETURN                                                       1

Function sernum:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 43
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 14
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 86
Branch analysis from position: 86
2 jumps found. (Code = 44) Position 1 = 90, Position 2 = 54
Branch analysis from position: 90
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 63
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 60, Position 2 = 74
Branch analysis from position: 60
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 82
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 84
Branch analysis from position: 84
2 jumps found. (Code = 44) Position 1 = 90, Position 2 = 54
Branch analysis from position: 90
Branch analysis from position: 54
Branch analysis from position: 82
1 jumps found. (Code = 42) Position 1 = 84
Branch analysis from position: 84
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 84
Branch analysis from position: 84
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 84
Branch analysis from position: 84
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 30
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 14
Branch analysis from position: 43
Branch analysis from position: 14
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 43
filename:       /in/LHe5q
function name:  sernum
number of ops:  92
compiled vars:  !0 = $check, !1 = $template, !2 = $parts, !3 = $i, !4 = $sernum, !5 = $hash
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   12     0  E >   RECV_INIT                                            !0      null
   14     1        ASSIGN                                                       !1, 'XXX99-XXX99-99XXX-99XXX'
   16     2        INIT_FCALL                                                   'explode'
          3        SEND_VAL                                                     '-'
          4        SEND_VAR                                                     !1
          5        SEND_VAL                                                     2
          6        DO_ICALL                                             $7      
          7        ASSIGN                                                       !2, $7
   17     8        ISSET_ISEMPTY_CV                                     ~9      !0
          9        BOOL_NOT                                             ~10     ~9
         10      > JMPZ                                                         ~10, ->43
   18    11    >   ASSIGN                                                       !0, ''
   19    12        ASSIGN                                                       !3, 0
         13      > JMP                                                          ->39
   20    14    >   FETCH_DIM_R                                          ~13     !2, 0
         15        FETCH_DIM_R                                          ~14     ~13, !3
   21    16        CASE                                                         ~14, 'X'
         17      > JMPNZ                                                        ~15, ->21
   22    18    >   CASE                                                         ~14, '9'
         19      > JMPNZ                                                        ~15, ->30
         20    > > JMP                                                          ->37
   21    21    >   INIT_FCALL                                                   'chr'
         22        INIT_FCALL                                                   'rand'
         23        SEND_VAL                                                     65
         24        SEND_VAL                                                     90
         25        DO_ICALL                                             $16     
         26        SEND_VAR                                                     $16
         27        DO_ICALL                                             $17     
         28        ASSIGN_OP                                         8          !0, $17
         29      > JMP                                                          ->37
   22    30    >   INIT_FCALL                                                   'rand'
         31        SEND_VAL                                                     0
         32        SEND_VAL                                                     9
         33        DO_ICALL                                             $19     
         34        CAST                                              6  ~20     $19
         35        ASSIGN_OP                                         8          !0, ~20
         36      > JMP                                                          ->37
         37    >   FREE                                                         ~14
   19    38        PRE_INC                                                      !3
         39    >   FETCH_DIM_R                                          ~23     !2, 0
         40        STRLEN                                               ~24     ~23
         41        IS_SMALLER                                                   !3, ~24
         42      > JMPNZ                                                        ~25, ->14
   27    43    >   CONCAT                                               ~26     !0, '-'
         44        ASSIGN                                                       !4, ~26
   28    45        INIT_FCALL                                                   'hash'
         46        SEND_VAL                                                     'sha256'
         47        FETCH_CONSTANT                                       ~28     'SECRET'
         48        CONCAT                                               ~29     !0, ~28
         49        SEND_VAL                                                     ~29
         50        DO_ICALL                                             $30     
         51        ASSIGN                                                       !5, $30
   30    52        ASSIGN                                                       !3, 0
         53      > JMP                                                          ->86
   31    54    >   FETCH_DIM_R                                          ~33     !2, 1
         55        FETCH_DIM_R                                          ~34     ~33, !3
   32    56        CASE                                                         ~34, 'X'
         57      > JMPNZ                                                        ~35, ->63
   33    58    >   CASE                                                         ~34, '9'
         59      > JMPNZ                                                        ~35, ->74
   34    60    >   CASE                                                         ~34, '-'
         61      > JMPNZ                                                        ~35, ->82
         62    > > JMP                                                          ->84
   32    63    >   INIT_FCALL                                                   'chr'
         64        INIT_FCALL                                                   'ord'
         65        FETCH_DIM_R                                          ~36     !5, !3
         66        SEND_VAL                                                     ~36
         67        DO_ICALL                                             $37     
         68        MOD                                                  ~38     $37, 26
         69        ADD                                                  ~39     65, ~38
         70        SEND_VAL                                                     ~39
         71        DO_ICALL                                             $40     
         72        ASSIGN_OP                                         8          !4, $40
         73      > JMP                                                          ->84
   33    74    >   INIT_FCALL                                                   'ord'
         75        FETCH_DIM_R                                          ~42     !5, !3
         76        SEND_VAL                                                     ~42
         77        DO_ICALL                                             $43     
         78        MOD                                                  ~44     $43, 10
         79        CAST                                              6  ~45     ~44
         80        ASSIGN_OP                                         8          !4, ~45
         81      > JMP                                                          ->84
   34    82    >   ASSIGN_OP                                         8          !4, '-'
         83      > JMP                                                          ->84
         84    >   FREE                                                         ~34
   30    85        PRE_INC                                                      !3
         86    >   FETCH_DIM_R                                          ~49     !2, 1
         87        STRLEN                                               ~50     ~49
         88        IS_SMALLER                                                   !3, ~50
         89      > JMPNZ                                                        ~51, ->54
   38    90    > > RETURN                                                       !4
   39    91*     > RETURN                                                       null

End of function sernum

Function check_sernum:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LHe5q
function name:  check_sernum
number of ops:  14
compiled vars:  !0 = $sernum, !1 = $parts
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   46     0  E >   RECV                                                 !0      
   48     1        INIT_FCALL                                                   'explode'
          2        SEND_VAL                                                     '-'
          3        SEND_VAR                                                     !0
          4        SEND_VAL                                                     2
          5        DO_ICALL                                             $2      
          6        ASSIGN                                                       !1, $2
   49     7        INIT_FCALL                                                   'sernum'
          8        FETCH_DIM_R                                          ~4      !1, 0
          9        SEND_VAL                                                     ~4
         10        DO_FCALL                                          0  $5      
         11        IS_IDENTICAL                                         ~6      !0, $5
         12      > RETURN                                                       ~6
   50    13*     > RETURN                                                       null

End of function check_sernum

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
166.84 ms | 2623 KiB | 23 Q