3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mcryptPadKey($key, $cipher, $blockMode) { $td = mcrypt_module_open($cipher, '', $blockMode, ''); $size = mcrypt_enc_get_key_size($td); mcrypt_module_close($td); //echo "- " . strlen($key) . " - " . $size . "\n\n"; if (strlen($key) === 0) { $key = str_repeat("\0", $size); } else if (strlen($key) > $size) { return substr($key, 0, $size); } else if (strlen($key) % $size) { $key = $key.str_repeat("\0", $size - (strlen($key) % $size)); } return $key; } function mcryptPadIV($iv, $cipher, $blockMode) { $td = mcrypt_module_open($cipher, '', $blockMode, ''); $size = mcrypt_enc_get_block_size($td); mcrypt_module_close($td); echo "- " . strlen($iv) . " - " . $size . "\n\n"; if (strlen($iv) != $size) { echo 'ok: ' . str_repeat("\0", $size); return str_repeat("\0", $size); } else { return $iv; } } function mcryptPadData($data, $cipher, $blockMode) { if (!is_scalar($data) && $data !== null) { return $data; } $td = mcrypt_module_open($cipher, '', $blockMode, ''); $size = mcrypt_enc_get_block_size($td); mcrypt_module_close($td); //echo "- " . strlen($data) . " - " . $size . "\n\n"; if (strlen($data) < $size) { return str_pad($data, $size, "\0"); } else { return $data; } } function mcryptDataConvert($mixed, $strict = false) { if (is_string($mixed)) { return $mixed; } if ( is_array($mixed) || is_object($mixed) && !method_exists($mixed, '__toString') || is_resource($mixed) ) { return $strict ? null : ''; } else if ($mixed === null) { return ''; } else { return (string)$mixed; } } function encode($input, $mode = "ASCII") { $res = ""; switch ($mode) { case "ASCII": for($i = 0; $i < strlen($input); $i++) $res .= ord($input[$i])."-"; break; case "hex": $unpack = unpack('H*', $input); $res = array_shift($unpack); break; default: $res = $input; break; } return $res; } $data = "52824616"; $key = "khfTiNtfrZ8554khfTiNtf\0\0"; $iv = base64_decode('w1Uy6MvHZNY='); $output = "hex"; echo $iv . "\n\n"; $my_key = $key; $my_key .= substr($my_key,0,8); $iv = $iv !== null ? $iv : "ÃU2èËÇdÖ"; $data = mcryptPadData($data, MCRYPT_3DES, MCRYPT_MODE_CBC); $my_key2 = mcryptPadKey($my_key, MCRYPT_3DES, MCRYPT_MODE_CBC); $iv2 = mcryptPadIV($iv, MCRYPT_3DES, MCRYPT_MODE_CBC); $crypt = mcrypt_encrypt(MCRYPT_3DES, $my_key2, $data, MCRYPT_MODE_CBC, $iv2); echo 'data: ' . $data . "\n"; echo 'key2: ' . $my_key2 . "\n"; echo 'iv2: ' . $iv2 . "\n"; echo $crypt . "\n\n"; echo encode($crypt, $output) . "\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mVnuJ
function name:  (null)
number of ops:  74
compiled vars:  !0 = $data, !1 = $key, !2 = $iv, !3 = $output, !4 = $my_key, !5 = $my_key2, !6 = $iv2, !7 = $crypt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   95     0  E >   ASSIGN                                                   !0, '52824616'
   96     1        ASSIGN                                                   !1, 'khfTiNtfrZ8554khfTiNtf%00%00'
   97     2        INIT_FCALL                                               'base64_decode'
          3        SEND_VAL                                                 'w1Uy6MvHZNY%3D'
          4        DO_ICALL                                         $10     
          5        ASSIGN                                                   !2, $10
   98     6        ASSIGN                                                   !3, 'hex'
  100     7        CONCAT                                           ~13     !2, '%0A%0A'
          8        ECHO                                                     ~13
  102     9        ASSIGN                                                   !4, !1
  103    10        INIT_FCALL                                               'substr'
         11        SEND_VAR                                                 !4
         12        SEND_VAL                                                 0
         13        SEND_VAL                                                 8
         14        DO_ICALL                                         $15     
         15        ASSIGN_OP                                     8          !4, $15
  104    16        TYPE_CHECK                                  1020          !2
         17      > JMPZ                                                     ~17, ->20
         18    >   QM_ASSIGN                                        ~18     !2
         19      > JMP                                                      ->21
         20    >   QM_ASSIGN                                        ~18     '%C3%83U2%C3%A8%C3%8B%C3%87d%C3%96'
         21    >   ASSIGN                                                   !2, ~18
  106    22        INIT_FCALL                                               'mcryptpaddata'
         23        SEND_VAR                                                 !0
         24        FETCH_CONSTANT                                   ~20     'MCRYPT_3DES'
         25        SEND_VAL                                                 ~20
         26        FETCH_CONSTANT                                   ~21     'MCRYPT_MODE_CBC'
         27        SEND_VAL                                                 ~21
         28        DO_FCALL                                      0  $22     
         29        ASSIGN                                                   !0, $22
  107    30        INIT_FCALL                                               'mcryptpadkey'
         31        SEND_VAR                                                 !4
         32        FETCH_CONSTANT                                   ~24     'MCRYPT_3DES'
         33        SEND_VAL                                                 ~24
         34        FETCH_CONSTANT                                   ~25     'MCRYPT_MODE_CBC'
         35        SEND_VAL                                                 ~25
         36        DO_FCALL                                      0  $26     
         37        ASSIGN                                                   !5, $26
  108    38        INIT_FCALL                                               'mcryptpadiv'
         39        SEND_VAR                                                 !2
         40        FETCH_CONSTANT                                   ~28     'MCRYPT_3DES'
         41        SEND_VAL                                                 ~28
         42        FETCH_CONSTANT                                   ~29     'MCRYPT_MODE_CBC'
         43        SEND_VAL                                                 ~29
         44        DO_FCALL                                      0  $30     
         45        ASSIGN                                                   !6, $30
  109    46        INIT_FCALL_BY_NAME                                       'mcrypt_encrypt'
         47        FETCH_CONSTANT                                   ~32     'MCRYPT_3DES'
         48        SEND_VAL_EX                                              ~32
         49        SEND_VAR_EX                                              !5
         50        SEND_VAR_EX                                              !0
         51        FETCH_CONSTANT                                   ~33     'MCRYPT_MODE_CBC'
         52        SEND_VAL_EX                                              ~33
         53        SEND_VAR_EX                                              !6
         54        DO_FCALL                                      0  $34     
         55        ASSIGN                                                   !7, $34
  111    56        CONCAT                                           ~36     'data%3A+', !0
         57        CONCAT                                           ~37     ~36, '%0A'
         58        ECHO                                                     ~37
  112    59        CONCAT                                           ~38     'key2%3A+', !5
         60        CONCAT                                           ~39     ~38, '%0A'
         61        ECHO                                                     ~39
  113    62        CONCAT                                           ~40     'iv2%3A+', !6
         63        CONCAT                                           ~41     ~40, '%0A'
         64        ECHO                                                     ~41
  115    65        CONCAT                                           ~42     !7, '%0A%0A'
         66        ECHO                                                     ~42
  117    67        INIT_FCALL                                               'encode'
         68        SEND_VAR                                                 !7
         69        SEND_VAR                                                 !3
         70        DO_FCALL                                      0  $43     
         71        CONCAT                                           ~44     $43, '%0A'
         72        ECHO                                                     ~44
         73      > RETURN                                                   1

Function mcryptpadkey:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 26
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 36
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 48
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
filename:       /in/mVnuJ
function name:  mcryptPadKey
number of ops:  50
compiled vars:  !0 = $key, !1 = $cipher, !2 = $blockMode, !3 = $td, !4 = $size
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    5     3        INIT_FCALL_BY_NAME                                       'mcrypt_module_open'
          4        SEND_VAR_EX                                              !1
          5        SEND_VAL_EX                                              ''
          6        SEND_VAR_EX                                              !2
          7        SEND_VAL_EX                                              ''
          8        DO_FCALL                                      0  $5      
          9        ASSIGN                                                   !3, $5
    6    10        INIT_FCALL_BY_NAME                                       'mcrypt_enc_get_key_size'
         11        SEND_VAR_EX                                              !3
         12        DO_FCALL                                      0  $7      
         13        ASSIGN                                                   !4, $7
    7    14        INIT_FCALL_BY_NAME                                       'mcrypt_module_close'
         15        SEND_VAR_EX                                              !3
         16        DO_FCALL                                      0          
   11    17        STRLEN                                           ~10     !0
         18        IS_IDENTICAL                                             ~10, 0
         19      > JMPZ                                                     ~11, ->26
   12    20    >   INIT_FCALL                                               'str_repeat'
         21        SEND_VAL                                                 '%00'
         22        SEND_VAR                                                 !4
         23        DO_ICALL                                         $12     
         24        ASSIGN                                                   !0, $12
   11    25      > JMP                                                      ->48
   13    26    >   STRLEN                                           ~14     !0
         27        IS_SMALLER                                               !4, ~14
         28      > JMPZ                                                     ~15, ->36
   14    29    >   INIT_FCALL                                               'substr'
         30        SEND_VAR                                                 !0
         31        SEND_VAL                                                 0
         32        SEND_VAR                                                 !4
         33        DO_ICALL                                         $16     
         34      > RETURN                                                   $16
   13    35*       JMP                                                      ->48
   15    36    >   STRLEN                                           ~17     !0
         37        MOD                                              ~18     ~17, !4
         38      > JMPZ                                                     ~18, ->48
   16    39    >   INIT_FCALL                                               'str_repeat'
         40        SEND_VAL                                                 '%00'
         41        STRLEN                                           ~19     !0
         42        MOD                                              ~20     ~19, !4
         43        SUB                                              ~21     !4, ~20
         44        SEND_VAL                                                 ~21
         45        DO_ICALL                                         $22     
         46        CONCAT                                           ~23     !0, $22
         47        ASSIGN                                                   !0, ~23
   19    48    > > RETURN                                                   !0
   20    49*     > RETURN                                                   null

End of function mcryptpadkey

Function mcryptpadiv:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 38
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mVnuJ
function name:  mcryptPadIV
number of ops:  40
compiled vars:  !0 = $iv, !1 = $cipher, !2 = $blockMode, !3 = $td, !4 = $size
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   24     3        INIT_FCALL_BY_NAME                                       'mcrypt_module_open'
          4        SEND_VAR_EX                                              !1
          5        SEND_VAL_EX                                              ''
          6        SEND_VAR_EX                                              !2
          7        SEND_VAL_EX                                              ''
          8        DO_FCALL                                      0  $5      
          9        ASSIGN                                                   !3, $5
   25    10        INIT_FCALL_BY_NAME                                       'mcrypt_enc_get_block_size'
         11        SEND_VAR_EX                                              !3
         12        DO_FCALL                                      0  $7      
         13        ASSIGN                                                   !4, $7
   26    14        INIT_FCALL_BY_NAME                                       'mcrypt_module_close'
         15        SEND_VAR_EX                                              !3
         16        DO_FCALL                                      0          
   28    17        STRLEN                                           ~10     !0
         18        CONCAT                                           ~11     '-+', ~10
         19        CONCAT                                           ~12     ~11, '+-+'
         20        CONCAT                                           ~13     ~12, !4
         21        CONCAT                                           ~14     ~13, '%0A%0A'
         22        ECHO                                                     ~14
   30    23        STRLEN                                           ~15     !0
         24        IS_NOT_EQUAL                                             !4, ~15
         25      > JMPZ                                                     ~16, ->38
   31    26    >   INIT_FCALL                                               'str_repeat'
         27        SEND_VAL                                                 '%00'
         28        SEND_VAR                                                 !4
         29        DO_ICALL                                         $17     
         30        CONCAT                                           ~18     'ok%3A+', $17
         31        ECHO                                                     ~18
   32    32        INIT_FCALL                                               'str_repeat'
         33        SEND_VAL                                                 '%00'
         34        SEND_VAR                                                 !4
         35        DO_ICALL                                         $19     
         36      > RETURN                                                   $19
   30    37*       JMP                                                      ->39
   34    38    > > RETURN                                                   !0
   36    39*     > RETURN                                                   null

End of function mcryptpadiv

Function mcryptpaddata:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 34
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/mVnuJ
function name:  mcryptPadData
number of ops:  36
compiled vars:  !0 = $data, !1 = $cipher, !2 = $blockMode, !3 = $td, !4 = $size
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   40     3        TYPE_CHECK                                  124  ~5      !0
          4        BOOL_NOT                                         ~6      ~5
          5      > JMPZ_EX                                          ~6      ~6, ->8
          6    >   TYPE_CHECK                                  1020  ~7      !0
          7        BOOL                                             ~6      ~7
          8    > > JMPZ                                                     ~6, ->10
   41     9    > > RETURN                                                   !0
   44    10    >   INIT_FCALL_BY_NAME                                       'mcrypt_module_open'
         11        SEND_VAR_EX                                              !1
         12        SEND_VAL_EX                                              ''
         13        SEND_VAR_EX                                              !2
         14        SEND_VAL_EX                                              ''
         15        DO_FCALL                                      0  $8      
         16        ASSIGN                                                   !3, $8
   45    17        INIT_FCALL_BY_NAME                                       'mcrypt_enc_get_block_size'
         18        SEND_VAR_EX                                              !3
         19        DO_FCALL                                      0  $10     
         20        ASSIGN                                                   !4, $10
   46    21        INIT_FCALL_BY_NAME                                       'mcrypt_module_close'
         22        SEND_VAR_EX                                              !3
         23        DO_FCALL                                      0          
   50    24        STRLEN                                           ~13     !0
         25        IS_SMALLER                                               ~13, !4
         26      > JMPZ                                                     ~14, ->34
   51    27    >   INIT_FCALL                                               'str_pad'
         28        SEND_VAR                                                 !0
         29        SEND_VAR                                                 !4
         30        SEND_VAL                                                 '%00'
         31        DO_ICALL                                         $15     
         32      > RETURN                                                   $15
   50    33*       JMP                                                      ->35
   53    34    > > RETURN                                                   !0
   55    35*     > RETURN                                                   null

End of function mcryptpaddata

Function mcryptdataconvert:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 16
Branch analysis from position: 7
2 jumps found. (Code = 46) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
2 jumps found. (Code = 47) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 26
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
Branch analysis from position: 15
Branch analysis from position: 16
filename:       /in/mVnuJ
function name:  mcryptDataConvert
number of ops:  33
compiled vars:  !0 = $mixed, !1 = $strict
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
   59     2        TYPE_CHECK                                   64          !0
          3      > JMPZ                                                     ~2, ->5
   60     4    > > RETURN                                                   !0
   63     5    >   TYPE_CHECK                                  128  ~3      !0
          6      > JMPNZ_EX                                         ~3      ~3, ->16
   64     7    >   TYPE_CHECK                                  256  ~4      !0
          8      > JMPZ_EX                                          ~4      ~4, ->15
          9    >   INIT_FCALL                                               'method_exists'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 '__toString'
         12        DO_ICALL                                         $5      
         13        BOOL_NOT                                         ~6      $5
         14        BOOL                                             ~4      ~6
         15    >   BOOL                                             ~3      ~4
         16    > > JMPNZ_EX                                         ~3      ~3, ->19
   65    17    >   TYPE_CHECK                                  512  ~7      !0
         18        BOOL                                             ~3      ~7
         19    > > JMPZ                                                     ~3, ->26
   67    20    > > JMPZ                                                     !1, ->23
         21    >   QM_ASSIGN                                        ~8      null
         22      > JMP                                                      ->24
         23    >   QM_ASSIGN                                        ~8      ''
         24    > > RETURN                                                   ~8
   63    25*       JMP                                                      ->32
   68    26    >   TYPE_CHECK                                    2          !0
         27      > JMPZ                                                     ~9, ->30
   69    28    > > RETURN                                                   ''
   68    29*       JMP                                                      ->32
   71    30    >   CAST                                          6  ~10     !0
         31      > RETURN                                                   ~10
   74    32*     > RETURN                                                   null

End of function mcryptdataconvert

Function encode:
Finding entry points
Branch analysis from position: 0
4 jumps found. (Code = 188) Position 1 = 9, Position 2 = 22, Position 3 = 32, Position 4 = 4
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 11
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 11
Branch analysis from position: 21
Branch analysis from position: 11
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 22
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 22
Branch analysis from position: 9
filename:       /in/mVnuJ
function name:  encode
number of ops:  36
compiled vars:  !0 = $input, !1 = $mode, !2 = $res, !3 = $i, !4 = $unpack
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      'ASCII'
   77     2        ASSIGN                                                   !2, ''
   78     3      > SWITCH_STRING                                            !1, [ 'ASCII':->9, 'hex':->22, ], ->32
   79     4    >   IS_EQUAL                                                 !1, 'ASCII'
          5      > JMPNZ                                                    ~6, ->9
   83     6    >   IS_EQUAL                                                 !1, 'hex'
          7      > JMPNZ                                                    ~6, ->22
          8    > > JMP                                                      ->32
   80     9    >   ASSIGN                                                   !3, 0
         10      > JMP                                                      ->18
   81    11    >   INIT_FCALL                                               'ord'
         12        FETCH_DIM_R                                      ~8      !0, !3
         13        SEND_VAL                                                 ~8
         14        DO_ICALL                                         $9      
         15        CONCAT                                           ~10     $9, '-'
         16        ASSIGN_OP                                     8          !2, ~10
   80    17        PRE_INC                                                  !3
         18    >   STRLEN                                           ~13     !0
         19        IS_SMALLER                                               !3, ~13
         20      > JMPNZ                                                    ~14, ->11
   82    21    > > JMP                                                      ->34
   84    22    >   INIT_FCALL                                               'unpack'
         23        SEND_VAL                                                 'H%2A'
         24        SEND_VAR                                                 !0
         25        DO_ICALL                                         $15     
         26        ASSIGN                                                   !4, $15
   85    27        INIT_FCALL                                               'array_shift'
         28        SEND_REF                                                 !4
         29        DO_ICALL                                         $17     
         30        ASSIGN                                                   !2, $17
   86    31      > JMP                                                      ->34
   88    32    >   ASSIGN                                                   !2, !0
   89    33      > JMP                                                      ->34
   91    34    > > RETURN                                                   !2
   92    35*     > RETURN                                                   null

End of function encode

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
290.28 ms | 1049 KiB | 25 Q