3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * Fill in all five below and click the blue 'eval();' button. * ------------------ */ $numberOfCase = -1; $unhashedServerSeed = ''; $nonce = -1; $clientSeed = ''; $qty = -1; /* ------------------ */ if ($numberOfCase < 0 || $unhashedServerSeed == 'e2acec00fc997ad5f6845b0be1a7a711655ad4afc5aacfbc5ab7cb00ffe922a1' || $nonce < 115 || $clientSeed == '4CW8z2nlUa7ljrdBP71JVOzgZpWX_Vd_4CW8z2nlUa7ljrdBP71JVOzgZpWX_Vd_' || $qty <= 2) { echo "Fill in details"; return; } define('MAX_HEX_SEGMENTS', 6); define('HEX_SEGMENT_SIZE', 2); define('BASE_FOR_HEX_CONVERSION', 256); define('HASH_TYPE', 'sha256'); function calculateDecimalValue(string $preResult): float { $decimalValue = 0; for ($i = 0; $i < MAX_HEX_SEGMENTS; $i++) { $hexValue = substr($preResult, HEX_SEGMENT_SIZE * $i, HEX_SEGMENT_SIZE); $decimalValue += hexdec($hexValue) / pow(BASE_FOR_HEX_CONVERSION, $i + 1); } return $decimalValue; } function getProvablyFairResult(string $init, string $serverSeed, int $qty): array { $preResult = hash_hmac(HASH_TYPE, $init, $serverSeed); $decimalValue = calculateDecimalValue($preResult); $result = (int) ($decimalValue * $qty) + 1; return [ 'preResult' => $preResult, 'result' => $result, ]; } $unhashedServerSeed = preg_replace( "/\r|\n/", "", $unhashedServerSeed); $clientSeed = preg_replace( "/\r|\n/", "", $clientSeed); $stringToHash = "$clientSeed-$numberOfCase-$nonce"; $result = getProvablyFairResult($stringToHash, $unhashedServerSeed, $qty); echo "Result: {$result['result']}";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
2 jumps found. (Code = 47) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
2 jumps found. (Code = 47) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
2 jumps found. (Code = 47) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Branch analysis from position: 15
Branch analysis from position: 12
Branch analysis from position: 9
filename:       /in/UKXXs
function name:  (null)
number of ops:  66
compiled vars:  !0 = $numberOfCase, !1 = $unhashedServerSeed, !2 = $nonce, !3 = $clientSeed, !4 = $qty, !5 = $stringToHash, !6 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   ASSIGN                                                   !0, -1
    7     1        ASSIGN                                                   !1, ''
    8     2        ASSIGN                                                   !2, -1
    9     3        ASSIGN                                                   !3, ''
   10     4        ASSIGN                                                   !4, -1
   14     5        IS_SMALLER                                       ~12     !0, 0
          6      > JMPNZ_EX                                         ~12     ~12, ->9
          7    >   IS_EQUAL                                         ~13     !1, 'e2acec00fc997ad5f6845b0be1a7a711655ad4afc5aacfbc5ab7cb00ffe922a1'
          8        BOOL                                             ~12     ~13
          9    > > JMPNZ_EX                                         ~12     ~12, ->12
         10    >   IS_SMALLER                                       ~14     !2, 115
         11        BOOL                                             ~12     ~14
         12    > > JMPNZ_EX                                         ~12     ~12, ->15
         13    >   IS_EQUAL                                         ~15     !3, '4CW8z2nlUa7ljrdBP71JVOzgZpWX_Vd_4CW8z2nlUa7ljrdBP71JVOzgZpWX_Vd_'
         14        BOOL                                             ~12     ~15
         15    > > JMPNZ_EX                                         ~12     ~12, ->18
         16    >   IS_SMALLER_OR_EQUAL                              ~16     !4, 2
         17        BOOL                                             ~12     ~16
         18    > > JMPZ                                                     ~12, ->21
   15    19    >   ECHO                                                     'Fill+in+details'
   16    20      > RETURN                                                   null
   19    21    >   INIT_FCALL                                               'define'
         22        SEND_VAL                                                 'MAX_HEX_SEGMENTS'
         23        SEND_VAL                                                 6
         24        DO_ICALL                                                 
   20    25        INIT_FCALL                                               'define'
         26        SEND_VAL                                                 'HEX_SEGMENT_SIZE'
         27        SEND_VAL                                                 2
         28        DO_ICALL                                                 
   21    29        INIT_FCALL                                               'define'
         30        SEND_VAL                                                 'BASE_FOR_HEX_CONVERSION'
         31        SEND_VAL                                                 256
         32        DO_ICALL                                                 
   22    33        INIT_FCALL                                               'define'
         34        SEND_VAL                                                 'HASH_TYPE'
         35        SEND_VAL                                                 'sha256'
         36        DO_ICALL                                                 
   45    37        INIT_FCALL                                               'preg_replace'
         38        SEND_VAL                                                 '%2F%0D%7C%0A%2F'
         39        SEND_VAL                                                 ''
         40        SEND_VAR                                                 !1
         41        DO_ICALL                                         $21     
         42        ASSIGN                                                   !1, $21
   46    43        INIT_FCALL                                               'preg_replace'
         44        SEND_VAL                                                 '%2F%0D%7C%0A%2F'
         45        SEND_VAL                                                 ''
         46        SEND_VAR                                                 !3
         47        DO_ICALL                                         $23     
         48        ASSIGN                                                   !3, $23
   47    49        ROPE_INIT                                     5  ~26     !3
         50        ROPE_ADD                                      1  ~26     ~26, '-'
         51        ROPE_ADD                                      2  ~26     ~26, !0
         52        ROPE_ADD                                      3  ~26     ~26, '-'
         53        ROPE_END                                      4  ~25     ~26, !2
         54        ASSIGN                                                   !5, ~25
   49    55        INIT_FCALL                                               'getprovablyfairresult'
         56        SEND_VAR                                                 !5
         57        SEND_VAR                                                 !1
         58        SEND_VAR                                                 !4
         59        DO_FCALL                                      0  $30     
         60        ASSIGN                                                   !6, $30
   51    61        NOP                                                      
         62        FETCH_DIM_R                                      ~32     !6, 'result'
         63        FAST_CONCAT                                      ~33     'Result%3A+', ~32
         64        ECHO                                                     ~33
         65      > RETURN                                                   1

Function calculatedecimalvalue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 4
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 4
Branch analysis from position: 28
Branch analysis from position: 4
filename:       /in/UKXXs
function name:  calculateDecimalValue
number of ops:  32
compiled vars:  !0 = $preResult, !1 = $decimalValue, !2 = $i, !3 = $hexValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        ASSIGN                                                   !1, 0
   27     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->25
   28     4    >   INIT_FCALL                                               'substr'
          5        SEND_VAR                                                 !0
          6        FETCH_CONSTANT                                   ~6      'HEX_SEGMENT_SIZE'
          7        MUL                                              ~7      !2, ~6
          8        SEND_VAL                                                 ~7
          9        FETCH_CONSTANT                                   ~8      'HEX_SEGMENT_SIZE'
         10        SEND_VAL                                                 ~8
         11        DO_ICALL                                         $9      
         12        ASSIGN                                                   !3, $9
   29    13        INIT_FCALL                                               'hexdec'
         14        SEND_VAR                                                 !3
         15        DO_ICALL                                         $11     
         16        INIT_FCALL                                               'pow'
         17        FETCH_CONSTANT                                   ~12     'BASE_FOR_HEX_CONVERSION'
         18        SEND_VAL                                                 ~12
         19        ADD                                              ~13     !2, 1
         20        SEND_VAL                                                 ~13
         21        DO_ICALL                                         $14     
         22        DIV                                              ~15     $11, $14
         23        ASSIGN_OP                                     1          !1, ~15
   27    24        PRE_INC                                                  !2
         25    >   FETCH_CONSTANT                                   ~18     'MAX_HEX_SEGMENTS'
         26        IS_SMALLER                                               !2, ~18
         27      > JMPNZ                                                    ~19, ->4
   31    28    >   VERIFY_RETURN_TYPE                                       !1
         29      > RETURN                                                   !1
   32    30*       VERIFY_RETURN_TYPE                                       
         31*     > RETURN                                                   null

End of function calculatedecimalvalue

Function getprovablyfairresult:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UKXXs
function name:  getProvablyFairResult
number of ops:  24
compiled vars:  !0 = $init, !1 = $serverSeed, !2 = $qty, !3 = $preResult, !4 = $decimalValue, !5 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   36     3        INIT_FCALL                                               'hash_hmac'
          4        FETCH_CONSTANT                                   ~6      'HASH_TYPE'
          5        SEND_VAL                                                 ~6
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $7      
          9        ASSIGN                                                   !3, $7
   37    10        INIT_FCALL                                               'calculatedecimalvalue'
         11        SEND_VAR                                                 !3
         12        DO_FCALL                                      0  $9      
         13        ASSIGN                                                   !4, $9
   38    14        MUL                                              ~11     !4, !2
         15        CAST                                          4  ~12     ~11
         16        ADD                                              ~13     ~12, 1
         17        ASSIGN                                                   !5, ~13
   40    18        INIT_ARRAY                                       ~15     !3, 'preResult'
   41    19        ADD_ARRAY_ELEMENT                                ~15     !5, 'result'
         20        VERIFY_RETURN_TYPE                                       ~15
         21      > RETURN                                                   ~15
   43    22*       VERIFY_RETURN_TYPE                                       
         23*     > RETURN                                                   null

End of function getprovablyfairresult

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.37 ms | 1109 KiB | 21 Q