3v4l.org

run code in 500+ PHP versions simultaneously
<?php $serverSeed = getenv('PF_SERVER_SEED') ?: '...'; // 32 hex $serverSalt = getenv('PF_SERVER_SALT') ?: '...'; // 16 hex $publicHash = getenv('PF_PUBLIC_HASH') ?: '...'; // 64 hex $clientSeed = getenv('PF_CLIENT_SEED') ?: '...'; $nonce = (int) (getenv('PF_NONCE') ?: 0); $maxRoll = (int) (getenv('PF_MAX_ROLL') ?: 100000); $expectedRoll = getenv('PF_EXPECTED_ROLL') !== false ? (int) getenv('PF_EXPECTED_ROLL') : null; // ─────────────────────────────────────────────────────────────────────────── $roll = (hexdec(substr(hash_hmac('sha512', $serverSeed, "$clientSeed-$nonce"), 0, 15)) % $maxRoll) + 1; $hashOk = hash_equals($publicHash, hash_hmac('sha256', $serverSeed, $serverSalt)); printf("public hash matches: %s\n", $hashOk ? 'YES' : 'NO'); printf("roll: %d (full 1..%d)\n", $roll, $maxRoll); if ($expectedRoll !== null) { printf("matches API roll (%d): %s\n", $expectedRoll, $roll === $expectedRoll ? 'YES' : 'NO'); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 49
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 80, Position 2 = 82
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 83
Branch analysis from position: 83
2 jumps found. (Code = 43) Position 1 = 92, Position 2 = 102
Branch analysis from position: 92
2 jumps found. (Code = 43) Position 1 = 97, Position 2 = 99
Branch analysis from position: 97
1 jumps found. (Code = 42) Position 1 = 100
Branch analysis from position: 100
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 99
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 102
Branch analysis from position: 82
2 jumps found. (Code = 43) Position 1 = 92, Position 2 = 102
Branch analysis from position: 92
Branch analysis from position: 102
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 80, Position 2 = 82
Branch analysis from position: 80
Branch analysis from position: 82
filename:       /in/N0ERl
function name:  (null)
number of ops:  103
compiled vars:  !0 = $serverSeed, !1 = $serverSalt, !2 = $publicHash, !3 = $clientSeed, !4 = $nonce, !5 = $maxRoll, !6 = $expectedRoll, !7 = $roll, !8 = $hashOk
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL                                                   'getenv'
          1        SEND_VAL                                                     'PF_SERVER_SEED'
          2        DO_ICALL                                             $9      
          3        JMP_SET                                              ~10     $9, ->5
          4        QM_ASSIGN                                            ~10     '...'
          5        ASSIGN                                                       !0, ~10
    5     6        INIT_FCALL                                                   'getenv'
          7        SEND_VAL                                                     'PF_SERVER_SALT'
          8        DO_ICALL                                             $12     
          9        JMP_SET                                              ~13     $12, ->11
         10        QM_ASSIGN                                            ~13     '...'
         11        ASSIGN                                                       !1, ~13
    6    12        INIT_FCALL                                                   'getenv'
         13        SEND_VAL                                                     'PF_PUBLIC_HASH'
         14        DO_ICALL                                             $15     
         15        JMP_SET                                              ~16     $15, ->17
         16        QM_ASSIGN                                            ~16     '...'
         17        ASSIGN                                                       !2, ~16
    7    18        INIT_FCALL                                                   'getenv'
         19        SEND_VAL                                                     'PF_CLIENT_SEED'
         20        DO_ICALL                                             $18     
         21        JMP_SET                                              ~19     $18, ->23
         22        QM_ASSIGN                                            ~19     '...'
         23        ASSIGN                                                       !3, ~19
    8    24        INIT_FCALL                                                   'getenv'
         25        SEND_VAL                                                     'PF_NONCE'
         26        DO_ICALL                                             $21     
         27        JMP_SET                                              ~22     $21, ->29
         28        QM_ASSIGN                                            ~22     0
         29        CAST                                              4  ~23     ~22
         30        ASSIGN                                                       !4, ~23
    9    31        INIT_FCALL                                                   'getenv'
         32        SEND_VAL                                                     'PF_MAX_ROLL'
         33        DO_ICALL                                             $25     
         34        JMP_SET                                              ~26     $25, ->36
         35        QM_ASSIGN                                            ~26     100000
         36        CAST                                              4  ~27     ~26
         37        ASSIGN                                                       !5, ~27
   10    38        INIT_FCALL                                                   'getenv'
         39        SEND_VAL                                                     'PF_EXPECTED_ROLL'
         40        DO_ICALL                                             $29     
         41        TYPE_CHECK                                      1018          $29
         42      > JMPZ                                                         ~30, ->49
         43    >   INIT_FCALL                                                   'getenv'
         44        SEND_VAL                                                     'PF_EXPECTED_ROLL'
         45        DO_ICALL                                             $31     
         46        CAST                                              4  ~32     $31
         47        QM_ASSIGN                                            ~33     ~32
         48      > JMP                                                          ->50
         49    >   QM_ASSIGN                                            ~33     null
         50    >   ASSIGN                                                       !6, ~33
   13    51        INIT_FCALL                                                   'hexdec'
         52        INIT_FCALL                                                   'hash_hmac'
         53        SEND_VAL                                                     'sha512'
         54        SEND_VAR                                                     !0
         55        ROPE_INIT                                         3  ~36     !3
         56        ROPE_ADD                                          1  ~36     ~36, '-'
         57        ROPE_END                                          2  ~35     ~36, !4
         58        SEND_VAL                                                     ~35
         59        DO_ICALL                                             $38     
         60        FRAMELESS_ICALL_3                substr              ~39     $38, 0
         61        OP_DATA                                                      15
         62        SEND_VAL                                                     ~39
         63        DO_ICALL                                             $40     
         64        MOD                                                  ~41     $40, !5
         65        ADD                                                  ~42     ~41, 1
         66        ASSIGN                                                       !7, ~42
   14    67        INIT_FCALL                                                   'hash_equals'
         68        SEND_VAR                                                     !2
         69        INIT_FCALL                                                   'hash_hmac'
         70        SEND_VAL                                                     'sha256'
         71        SEND_VAR                                                     !0
         72        SEND_VAR                                                     !1
         73        DO_ICALL                                             $44     
         74        SEND_VAR                                                     $44
         75        DO_ICALL                                             $45     
         76        ASSIGN                                                       !8, $45
   16    77        INIT_FCALL                                                   'printf'
         78        SEND_VAL                                                     'public+hash+matches%3A+%25s%0A'
         79      > JMPZ                                                         !8, ->82
         80    >   QM_ASSIGN                                            ~47     'YES'
         81      > JMP                                                          ->83
         82    >   QM_ASSIGN                                            ~47     'NO'
         83    >   SEND_VAL                                                     ~47
         84        DO_ICALL                                                     
   17    85        INIT_FCALL                                                   'printf'
         86        SEND_VAL                                                     'roll%3A+%25d++%28full+1..%25d%29%0A'
         87        SEND_VAR                                                     !7
         88        SEND_VAR                                                     !5
         89        DO_ICALL                                                     
   18    90        TYPE_CHECK                                      1020          !6
         91      > JMPZ                                                         ~50, ->102
   19    92    >   INIT_FCALL                                                   'printf'
         93        SEND_VAL                                                     'matches+API+roll+%28%25d%29%3A+%25s%0A'
         94        SEND_VAR                                                     !6
         95        IS_IDENTICAL                                                 !7, !6
         96      > JMPZ                                                         ~51, ->99
         97    >   QM_ASSIGN                                            ~52     'YES'
         98      > JMP                                                          ->100
         99    >   QM_ASSIGN                                            ~52     'NO'
        100    >   SEND_VAL                                                     ~52
        101        DO_ICALL                                                     
   20   102    > > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
163.14 ms | 1406 KiB | 18 Q