3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gdr_encode($val) { $str = ''; while ($val > 0) { $str .= chr($val & 0xFF); $val = $val >> 8; } return str_replace(array('/', '='), array('_', ''), base64_encode($str)); } function gdr_decode($str) { $bin = base64_decode(str_replace('_', '/', $str)); $val = 0; for ($i=0; $i<strlen($bin); $i++) { $val |= ord($bin[$i]) << $i*8; } return $val; } mt_srand(42); // seed rng for semi-consistent values for ($i=0; $i<32; $i++) { $val = 1<<$i; $val += mt_rand(0, $val/2); $enc = gdr_encode($val); $dec = gdr_decode($enc); if ($val === $dec) { echo "$enc $val\n"; } else { echo "$enc $valĀ ERROR: gdr_decode($enc) == $dec\n"; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 5
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 29
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 5
Branch analysis from position: 41
Branch analysis from position: 5
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 5
Branch analysis from position: 41
Branch analysis from position: 5
filename:       /in/hkdm0
function name:  (null)
number of ops:  42
compiled vars:  !0 = $i, !1 = $val, !2 = $enc, !3 = $dec, !4 = $valĀ ERROR
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   INIT_FCALL                                               'mt_srand'
          1        SEND_VAL                                                 42
          2        DO_ICALL                                                 
   22     3        ASSIGN                                                   !0, 0
          4      > JMP                                                      ->39
   23     5    >   SL                                               ~7      1, !0
          6        ASSIGN                                                   !1, ~7
   24     7        INIT_FCALL                                               'mt_rand'
          8        SEND_VAL                                                 0
          9        DIV                                              ~9      !1, 2
         10        SEND_VAL                                                 ~9
         11        DO_ICALL                                         $10     
         12        ASSIGN_OP                                     1          !1, $10
   25    13        INIT_FCALL                                               'gdr_encode'
         14        SEND_VAR                                                 !1
         15        DO_FCALL                                      0  $12     
         16        ASSIGN                                                   !2, $12
   26    17        INIT_FCALL                                               'gdr_decode'
         18        SEND_VAR                                                 !2
         19        DO_FCALL                                      0  $14     
         20        ASSIGN                                                   !3, $14
   27    21        IS_IDENTICAL                                             !1, !3
         22      > JMPZ                                                     ~16, ->29
   28    23    >   ROPE_INIT                                     4  ~18     !2
         24        ROPE_ADD                                      1  ~18     ~18, '+'
         25        ROPE_ADD                                      2  ~18     ~18, !1
         26        ROPE_END                                      3  ~17     ~18, '%0A'
         27        ECHO                                                     ~17
         28      > JMP                                                      ->38
   30    29    >   ROPE_INIT                                     8  ~21     !2
         30        ROPE_ADD                                      1  ~21     ~21, '+'
         31        ROPE_ADD                                      2  ~21     ~21, !4
         32        ROPE_ADD                                      3  ~21     ~21, '%3A+gdr_decode%28'
         33        ROPE_ADD                                      4  ~21     ~21, !2
         34        ROPE_ADD                                      5  ~21     ~21, '%29+%3D%3D+'
         35        ROPE_ADD                                      6  ~21     ~21, !3
         36        ROPE_END                                      7  ~20     ~21, '%0A'
         37        ECHO                                                     ~20
   22    38    >   PRE_INC                                                  !0
         39    >   IS_SMALLER                                               !0, 32
         40      > JMPNZ                                                    ~26, ->5
   32    41    > > RETURN                                                   1

Function gdr_encode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 3
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 3
Branch analysis from position: 12
Branch analysis from position: 3
filename:       /in/hkdm0
function name:  gdr_encode
number of ops:  22
compiled vars:  !0 = $val, !1 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, ''
    5     2      > JMP                                                      ->10
    6     3    >   INIT_FCALL                                               'chr'
          4        BW_AND                                           ~3      !0, 255
          5        SEND_VAL                                                 ~3
          6        DO_ICALL                                         $4      
          7        ASSIGN_OP                                     8          !1, $4
    7     8        SR                                               ~6      !0, 8
          9        ASSIGN                                                   !0, ~6
    5    10    >   IS_SMALLER                                               0, !0
         11      > JMPNZ                                                    ~8, ->3
    9    12    >   INIT_FCALL                                               'str_replace'
         13        SEND_VAL                                                 <array>
         14        SEND_VAL                                                 <array>
         15        INIT_FCALL                                               'base64_encode'
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                         $9      
         18        SEND_VAR                                                 $9
         19        DO_ICALL                                         $10     
         20      > RETURN                                                   $10
   10    21*     > RETURN                                                   null

End of function gdr_encode

Function gdr_decode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 13
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 13
Branch analysis from position: 24
Branch analysis from position: 13
filename:       /in/hkdm0
function name:  gdr_decode
number of ops:  26
compiled vars:  !0 = $str, !1 = $bin, !2 = $val, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        INIT_FCALL                                               'base64_decode'
          2        INIT_FCALL                                               'str_replace'
          3        SEND_VAL                                                 '_'
          4        SEND_VAL                                                 '%2F'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                         $5      
          9        ASSIGN                                                   !1, $5
   14    10        ASSIGN                                                   !2, 0
   15    11        ASSIGN                                                   !3, 0
         12      > JMP                                                      ->21
   16    13    >   INIT_FCALL                                               'ord'
         14        FETCH_DIM_R                                      ~9      !1, !3
         15        SEND_VAL                                                 ~9
         16        DO_ICALL                                         $10     
         17        MUL                                              ~11     !3, 8
         18        SL                                               ~12     $10, ~11
         19        ASSIGN_OP                                     9          !2, ~12
   15    20        PRE_INC                                                  !3
         21    >   STRLEN                                           ~15     !1
         22        IS_SMALLER                                               !3, ~15
         23      > JMPNZ                                                    ~16, ->13
   18    24    > > RETURN                                                   !2
   19    25*     > RETURN                                                   null

End of function gdr_decode

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.11 ms | 1407 KiB | 29 Q