3v4l.org

run code in 300+ PHP versions simultaneously
<?php //bk2020 cc0 // SipHash-2-4 // Aumasson and Bernstein 2012, https://131002.net/siphash/ // https://github.com/jedisct1/libsodium/tree/master/src/libsodium/crypto_shorthash // https://github.com/php/php-src/tree/master/ext/sodium/libsodium.c#L472 function bytes_as_hex(&$str, $len=null) { if( !$len ) { $len = strlen($str); } // zero-based array index for unpack, kennwhite 2005: // https://www.php.net/manual/en/function.unpack.php#45188 $arrhead = array_merge( unpack('C*', substr($str,0,$len)) ); return array_reduce( $arrhead, function($a,$b) { return ($b>15) ? $a.dechex($b) : $a.'0'.dechex($b); }, '' ); } $SIPHASH = null; if( function_exists('\sodium_crypto_shorthash') ) { $SIPHASH = 'sodium_crypto_shorthash'; } else if( function_exists('\Sodium\crypto_shorthash') ) { $SIPHASH = '\Sodium\crypto_shorthash'; } else { die('Unable to test SipHash-2-4 using sodium_crypto_shorthash'); } $SIPKEY = '1234567890abcdef'; // 16-byte key for SipHash-2-4 echo '# ', $SIPHASH, PHP_EOL; // thanks to: https://3v4l.org/EsGSU // (note: bin2hex won't print leading zero on byte values <16) for ($i = 0; $i < 256; ++$i) { $hsh = $SIPHASH( bin2hex(chr(($i & 0x3F) | 0x80)), $SIPKEY ); echo $i, "\t", bytes_as_hex($hsh,8), PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 20
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 20
Branch analysis from position: 44
Branch analysis from position: 20
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 13
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/IpC4L
function name:  (null)
number of ops:  45
compiled vars:  !0 = $SIPHASH, !1 = $SIPKEY, !2 = $i, !3 = $hsh
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   ASSIGN                                                   !0, null
   21     1        INIT_FCALL                                               'function_exists'
          2        SEND_VAL                                                 '%5Csodium_crypto_shorthash'
          3        DO_ICALL                                         $5      
          4      > JMPZ                                                     $5, ->7
   22     5    >   ASSIGN                                                   !0, 'sodium_crypto_shorthash'
          6      > JMP                                                      ->14
   24     7    >   INIT_FCALL                                               'function_exists'
          8        SEND_VAL                                                 '%5CSodium%5Ccrypto_shorthash'
          9        DO_ICALL                                         $7      
         10      > JMPZ                                                     $7, ->13
   25    11    >   ASSIGN                                                   !0, '%5CSodium%5Ccrypto_shorthash'
         12      > JMP                                                      ->14
   28    13    > > EXIT                                                     'Unable+to+test+SipHash-2-4+using+sodium_crypto_shorthash'
   31    14    >   ASSIGN                                                   !1, '1234567890abcdef'
   33    15        ECHO                                                     '%23+'
         16        ECHO                                                     !0
         17        ECHO                                                     '%0A'
   37    18        ASSIGN                                                   !2, 0
         19      > JMP                                                      ->42
   38    20    >   INIT_DYNAMIC_CALL                                        !0
         21        INIT_FCALL                                               'bin2hex'
         22        INIT_FCALL                                               'chr'
         23        BW_AND                                           ~11     !2, 63
         24        BW_OR                                            ~12     ~11, 128
         25        SEND_VAL                                                 ~12
         26        DO_ICALL                                         $13     
         27        SEND_VAR                                                 $13
         28        DO_ICALL                                         $14     
         29        SEND_VAR_NO_REF_EX                                       $14
         30        SEND_VAR_EX                                              !1
         31        DO_FCALL                                      0  $15     
         32        ASSIGN                                                   !3, $15
   39    33        ECHO                                                     !2
         34        ECHO                                                     '%09'
         35        INIT_FCALL                                               'bytes_as_hex'
         36        SEND_REF                                                 !3
         37        SEND_VAL                                                 8
         38        DO_FCALL                                      0  $17     
         39        ECHO                                                     $17
         40        ECHO                                                     '%0A'
   37    41        PRE_INC                                                  !2
         42    >   IS_SMALLER                                               !2, 256
         43      > JMPNZ                                                    ~19, ->20
   40    44    > > RETURN                                                   1

Function bytes_as_hex:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/IpC4L
function name:  bytes_as_hex
number of ops:  27
compiled vars:  !0 = $str, !1 = $len, !2 = $arrhead
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
    9     2        BOOL_NOT                                         ~3      !1
          3      > JMPZ                                                     ~3, ->6
          4    >   STRLEN                                           ~4      !0
          5        ASSIGN                                                   !1, ~4
   13     6    >   INIT_FCALL                                               'array_merge'
          7        INIT_FCALL                                               'unpack'
          8        SEND_VAL                                                 'C%2A'
          9        INIT_FCALL                                               'substr'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 0
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $6      
         14        SEND_VAR                                                 $6
         15        DO_ICALL                                         $7      
         16        SEND_VAR                                                 $7
         17        DO_ICALL                                         $8      
         18        ASSIGN                                                   !2, $8
   15    19        INIT_FCALL                                               'array_reduce'
         20        SEND_VAR                                                 !2
         21        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FIpC4L%3A15%240'
   17    22        SEND_VAL                                                 ~10
         23        SEND_VAL                                                 ''
         24        DO_ICALL                                         $11     
         25      > RETURN                                                   $11
   18    26*     > RETURN                                                   null

End of function bytes_as_hex

Function %00%7Bclosure%7D%2Fin%2FIpC4L%3A15%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IpC4L
function name:  {closure}
number of ops:  18
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   16     2        IS_SMALLER                                               15, !1
          3      > JMPZ                                                     ~2, ->10
          4    >   INIT_FCALL                                               'dechex'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $3      
          7        CONCAT                                           ~4      !0, $3
          8        QM_ASSIGN                                        ~5      ~4
          9      > JMP                                                      ->16
         10    >   CONCAT                                           ~6      !0, '0'
         11        INIT_FCALL                                               'dechex'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $7      
         14        CONCAT                                           ~8      ~6, $7
         15        QM_ASSIGN                                        ~5      ~8
         16    > > RETURN                                                   ~5
   17    17*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FIpC4L%3A15%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.99 ms | 1407 KiB | 30 Q