3v4l.org

run code in 300+ PHP versions simultaneously
<?php function OTP($input, $pad) { $inputlen = strlen($input); $padlen = strlen($pad); $inputbytes = unpack("C*", $input); //Pack C* will convert a string into a byte array, such as 'abc' to Array(0x61, 0x62, 0x63) $padbytes = unpack("C*", $pad); $output = ""; for($i = 0; $i < $inputlen; $i++) //Loop through the input string $output .= chr($inputbytes[$i + 1] ^ $padbytes[$i % $padlen + 1]); return $output; } $result = OTP("This is a long sentence", "ABC"); $bytes = unpack("C*", $result); echo "Bytes: "; foreach($bytes as $byte) echo $byte . " "; echo "\nEncrypted string: "; echo $result;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/DHniG
function name:  (null)
number of ops:  20
compiled vars:  !0 = $result, !1 = $bytes, !2 = $byte
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                               'otp'
          1        SEND_VAL                                                 'This+is+a+long+sentence'
          2        SEND_VAL                                                 'ABC'
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !0, $3
   16     5        INIT_FCALL                                               'unpack'
          6        SEND_VAL                                                 'C%2A'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $5      
          9        ASSIGN                                                   !1, $5
   17    10        ECHO                                                     'Bytes%3A+'
   18    11      > FE_RESET_R                                       $7      !1, ->16
         12    > > FE_FETCH_R                                               $7, !2, ->16
         13    >   CONCAT                                           ~8      !2, '+'
         14        ECHO                                                     ~8
         15      > JMP                                                      ->12
         16    >   FE_FREE                                                  $7
   19    17        ECHO                                                     '%0AEncrypted+string%3A+'
   20    18        ECHO                                                     !0
         19      > RETURN                                                   1

Function otp:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 19
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 19
Branch analysis from position: 32
Branch analysis from position: 19
filename:       /in/DHniG
function name:  OTP
number of ops:  34
compiled vars:  !0 = $input, !1 = $pad, !2 = $inputlen, !3 = $padlen, !4 = $inputbytes, !5 = $padbytes, !6 = $output, !7 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        STRLEN                                           ~8      !0
          3        ASSIGN                                                   !2, ~8
    5     4        STRLEN                                           ~10     !1
          5        ASSIGN                                                   !3, ~10
    6     6        INIT_FCALL                                               'unpack'
          7        SEND_VAL                                                 'C%2A'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $12     
         10        ASSIGN                                                   !4, $12
    7    11        INIT_FCALL                                               'unpack'
         12        SEND_VAL                                                 'C%2A'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $14     
         15        ASSIGN                                                   !5, $14
    9    16        ASSIGN                                                   !6, ''
   10    17        ASSIGN                                                   !7, 0
         18      > JMP                                                      ->30
   11    19    >   INIT_FCALL                                               'chr'
         20        ADD                                              ~18     !7, 1
         21        FETCH_DIM_R                                      ~19     !4, ~18
         22        MOD                                              ~20     !7, !3
         23        ADD                                              ~21     ~20, 1
         24        FETCH_DIM_R                                      ~22     !5, ~21
         25        BW_XOR                                           ~23     ~19, ~22
         26        SEND_VAL                                                 ~23
         27        DO_ICALL                                         $24     
         28        ASSIGN_OP                                     8          !6, $24
   10    29        PRE_INC                                                  !7
         30    >   IS_SMALLER                                               !7, !2
         31      > JMPNZ                                                    ~27, ->19
   12    32    > > RETURN                                                   !6
   13    33*     > RETURN                                                   null

End of function otp

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.71 ms | 1403 KiB | 18 Q