3v4l.org

run code in 300+ PHP versions simultaneously
<?php function crypto_rand_secure($min, $max) { $range = $max - $min; if ($range < 1) return $min; // not so random... $log = ceil(log($range, 2)); $bytes = (int) ($log / 8) + 1; // length in bytes $bits = (int) $log + 1; // length in bits $filter = (int) (1 << $bits) - 1; // set all lower bits to 1 do { $rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes))); $rnd = $rnd & $filter; // discard irrelevant bits } while ($rnd >= $range); return $min + $rnd; } function getToken($length) { $token = ""; $codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $codeAlphabet.= "abcdefghijklmnopqrstuvwxyz"; $codeAlphabet.= "0123456789"; $max = strlen($codeAlphabet) - 1; for ($i=0; $i < $length; $i++) { $token .= $codeAlphabet[crypto_rand_secure(0, $max)]; } return $token; } echo getToken(30); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pS2Qd
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   INIT_FCALL                                               'gettoken'
          1        SEND_VAL                                                 30
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
   32     4      > RETURN                                                   1

Function crypto_rand_secure:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 26
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/pS2Qd
function name:  crypto_rand_secure
number of ops:  43
compiled vars:  !0 = $min, !1 = $max, !2 = $range, !3 = $log, !4 = $bytes, !5 = $bits, !6 = $filter, !7 = $rnd
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        SUB                                              ~8      !1, !0
          3        ASSIGN                                                   !2, ~8
    6     4        IS_SMALLER                                               !2, 1
          5      > JMPZ                                                     ~10, ->7
          6    > > RETURN                                                   !0
    7     7    >   INIT_FCALL                                               'ceil'
          8        INIT_FCALL                                               'log'
          9        SEND_VAR                                                 !2
         10        SEND_VAL                                                 2
         11        DO_ICALL                                         $11     
         12        SEND_VAR                                                 $11
         13        DO_ICALL                                         $12     
         14        ASSIGN                                                   !3, $12
    8    15        DIV                                              ~14     !3, 8
         16        CAST                                          4  ~15     ~14
         17        ADD                                              ~16     ~15, 1
         18        ASSIGN                                                   !4, ~16
    9    19        CAST                                          4  ~18     !3
         20        ADD                                              ~19     ~18, 1
         21        ASSIGN                                                   !5, ~19
   10    22        SL                                               ~21     1, !5
         23        CAST                                          4  ~22     ~21
         24        SUB                                              ~23     ~22, 1
         25        ASSIGN                                                   !6, ~23
   12    26    >   INIT_FCALL                                               'hexdec'
         27        INIT_FCALL                                               'bin2hex'
         28        INIT_FCALL_BY_NAME                                       'openssl_random_pseudo_bytes'
         29        SEND_VAR_EX                                              !4
         30        DO_FCALL                                      0  $25     
         31        SEND_VAR                                                 $25
         32        DO_ICALL                                         $26     
         33        SEND_VAR                                                 $26
         34        DO_ICALL                                         $27     
         35        ASSIGN                                                   !7, $27
   13    36        BW_AND                                           ~29     !7, !6
         37        ASSIGN                                                   !7, ~29
   14    38        IS_SMALLER_OR_EQUAL                                      !2, !7
         39      > JMPNZ                                                    ~31, ->26
   15    40    >   ADD                                              ~32     !0, !7
         41      > RETURN                                                   ~32
   16    42*     > RETURN                                                   null

End of function crypto_rand_secure

Function gettoken:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 10
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 10
Branch analysis from position: 19
Branch analysis from position: 10
filename:       /in/pS2Qd
function name:  getToken
number of ops:  21
compiled vars:  !0 = $length, !1 = $token, !2 = $codeAlphabet, !3 = $max, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   20     1        ASSIGN                                                   !1, ''
   21     2        ASSIGN                                                   !2, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
   22     3        ASSIGN_OP                                     8          !2, 'abcdefghijklmnopqrstuvwxyz'
   23     4        ASSIGN_OP                                     8          !2, '0123456789'
   24     5        STRLEN                                           ~9      !2
          6        SUB                                              ~10     ~9, 1
          7        ASSIGN                                                   !3, ~10
   25     8        ASSIGN                                                   !4, 0
          9      > JMP                                                      ->17
   26    10    >   INIT_FCALL                                               'crypto_rand_secure'
         11        SEND_VAL                                                 0
         12        SEND_VAR                                                 !3
         13        DO_FCALL                                      0  $13     
         14        FETCH_DIM_R                                      ~14     !2, $13
         15        ASSIGN_OP                                     8          !1, ~14
   25    16        PRE_INC                                                  !4
         17    >   IS_SMALLER                                               !4, !0
         18      > JMPNZ                                                    ~17, ->10
   28    19    > > RETURN                                                   !1
   29    20*     > RETURN                                                   null

End of function gettoken

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
130.36 ms | 1021 KiB | 19 Q