3v4l.org

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

End of function getprovablyfairresult

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.15 ms | 1018 KiB | 21 Q