3v4l.org

run code in 500+ PHP versions simultaneously
<?php /* * Fill in all four below and click the blue 'eval();' button. * ------------------ */ $server_seed = ""; $client_seed = ""; $game_id = ""; $mine_count = 3; /* ------------------ */ if ($server_seed == '' || $client_seed === "" || $game_id == '') { echo "Fill in details"; return; } $grid_size = 25; // Same hex-to-decimal-via-bcmath approach as the other games, reused per shuffle step. function hmac_mod($server_seed, $message, $modulus) { $hmac_hash = hash_hmac('sha256', $message, $server_seed); $decimal_value = '0'; $length = strlen($hmac_hash); for ($i = 0; $i < $length; $i++) { $decimal_value = bcmul($decimal_value, '16'); $decimal_value = bcadd($decimal_value, hexdec($hmac_hash[$i])); } return (int) bcmod($decimal_value, (string) $modulus); } // Fisher-Yates shuffle over all 25 tiles — one HMAC draw per swap, identical // to get_mines_positions() server-side. Message per step i is // "{client_seed}-{game_id}-{i}", modulus is i+1. $positions = range(0, $grid_size - 1); for ($i = $grid_size - 1; $i > 0; $i--) { $message = $client_seed . "-" . $game_id . "-" . $i; $r = hmac_mod($server_seed, $message, $i + 1); $tmp = $positions[$i]; $positions[$i] = $positions[$r]; $positions[$r] = $tmp; } $mine_positions = array_slice($positions, 0, $mine_count); sort($mine_positions); echo "Mine positions: " . implode(", ", $mine_positions); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 47) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 24
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 24
Branch analysis from position: 46
Branch analysis from position: 24
Branch analysis from position: 11
Branch analysis from position: 8
filename:       /in/4umdA
function name:  (null)
number of ops:  59
compiled vars:  !0 = $server_seed, !1 = $client_seed, !2 = $game_id, !3 = $mine_count, !4 = $grid_size, !5 = $positions, !6 = $i, !7 = $message, !8 = $r, !9 = $tmp, !10 = $mine_positions
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                       !0, ''
    6     1        ASSIGN                                                       !1, ''
    7     2        ASSIGN                                                       !2, ''
    8     3        ASSIGN                                                       !3, 3
   11     4        IS_EQUAL                                             ~15     !0, ''
          5      > JMPNZ_EX                                             ~15     ~15, ->8
          6    >   IS_IDENTICAL                                         ~16     !1, ''
          7        BOOL                                                 ~15     ~16
          8    > > JMPNZ_EX                                             ~15     ~15, ->11
          9    >   IS_EQUAL                                             ~17     !2, ''
         10        BOOL                                                 ~15     ~17
         11    > > JMPZ                                                         ~15, ->14
   12    12    >   ECHO                                                         'Fill+in+details'
   13    13      > RETURN                                                       null
   16    14    >   ASSIGN                                                       !4, 25
   33    15        INIT_FCALL                                                   'range'
         16        SEND_VAL                                                     0
         17        SUB                                                  ~19     !4, 1
         18        SEND_VAL                                                     ~19
         19        DO_ICALL                                             $20     
         20        ASSIGN                                                       !5, $20
   34    21        SUB                                                  ~22     !4, 1
         22        ASSIGN                                                       !6, ~22
         23      > JMP                                                          ->44
   35    24    >   CONCAT                                               ~24     !1, '-'
         25        CONCAT                                               ~25     ~24, !2
         26        CONCAT                                               ~26     ~25, '-'
         27        CONCAT                                               ~27     ~26, !6
         28        ASSIGN                                                       !7, ~27
   36    29        INIT_FCALL                                                   'hmac_mod'
         30        SEND_VAR                                                     !0
         31        SEND_VAR                                                     !7
         32        ADD                                                  ~29     !6, 1
         33        SEND_VAL                                                     ~29
         34        DO_FCALL                                          0  $30     
         35        ASSIGN                                                       !8, $30
   37    36        FETCH_DIM_R                                          ~32     !5, !6
         37        ASSIGN                                                       !9, ~32
   38    38        FETCH_DIM_R                                          ~35     !5, !8
         39        ASSIGN_DIM                                                   !5, !6
         40        OP_DATA                                                      ~35
   39    41        ASSIGN_DIM                                                   !5, !8
         42        OP_DATA                                                      !9
   34    43        PRE_DEC                                                      !6
         44    >   IS_SMALLER                                                   0, !6
         45      > JMPNZ                                                        ~38, ->24
   42    46    >   INIT_FCALL                                                   'array_slice'
         47        SEND_VAR                                                     !5
         48        SEND_VAL                                                     0
         49        SEND_VAR                                                     !3
         50        DO_ICALL                                             $39     
         51        ASSIGN                                                       !10, $39
   43    52        INIT_FCALL                                                   'sort'
         53        SEND_REF                                                     !10
         54        DO_ICALL                                                     
   45    55        FRAMELESS_ICALL_2                implode             ~42     '%2C+', !10
         56        CONCAT                                               ~43     'Mine+positions%3A+', ~42
         57        ECHO                                                         ~43
   46    58      > RETURN                                                       1

Function hmac_mod:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 14
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 14
Branch analysis from position: 31
Branch analysis from position: 14
filename:       /in/4umdA
function name:  hmac_mod
number of ops:  39
compiled vars:  !0 = $server_seed, !1 = $message, !2 = $modulus, !3 = $hmac_hash, !4 = $decimal_value, !5 = $length, !6 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   20     3        INIT_FCALL                                                   'hash_hmac'
          4        SEND_VAL                                                     'sha256'
          5        SEND_VAR                                                     !1
          6        SEND_VAR                                                     !0
          7        DO_ICALL                                             $7      
          8        ASSIGN                                                       !3, $7
   21     9        ASSIGN                                                       !4, '0'
   22    10        STRLEN                                               ~10     !3
         11        ASSIGN                                                       !5, ~10
   23    12        ASSIGN                                                       !6, 0
         13      > JMP                                                          ->29
   24    14    >   INIT_FCALL_BY_NAME                                           'bcmul'
         15        SEND_VAR_EX                                                  !4
         16        SEND_VAL_EX                                                  '16'
         17        DO_FCALL                                          0  $13     
         18        ASSIGN                                                       !4, $13
   25    19        INIT_FCALL_BY_NAME                                           'bcadd'
         20        SEND_VAR_EX                                                  !4
         21        INIT_FCALL                                                   'hexdec'
         22        FETCH_DIM_R                                          ~15     !3, !6
         23        SEND_VAL                                                     ~15
         24        DO_ICALL                                             $16     
         25        SEND_VAR_NO_REF_EX                                           $16
         26        DO_FCALL                                          0  $17     
         27        ASSIGN                                                       !4, $17
   23    28        PRE_INC                                                      !6
         29    >   IS_SMALLER                                                   !6, !5
         30      > JMPNZ                                                        ~20, ->14
   27    31    >   INIT_FCALL_BY_NAME                                           'bcmod'
         32        SEND_VAR_EX                                                  !4
         33        CAST                                              6  ~21     !2
         34        SEND_VAL_EX                                                  ~21
         35        DO_FCALL                                          0  $22     
         36        CAST                                              4  ~23     $22
         37      > RETURN                                                       ~23
   28    38*     > RETURN                                                       null

End of function hmac_mod

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
158.91 ms | 781 KiB | 14 Q