3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { protected $mcrypt_cipher = MCRYPT_RIJNDAEL_128; protected $mcrypt_mode = MCRYPT_MODE_CBC; public function decrypt($key, $iv, $encrypted) { return mcrypt_decrypt($this->mcrypt_cipher, $key, base64_decode($encrypted), $this->mcrypt_mode, $iv); } public function encrypt($key, $iv, $password) { $block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); $padding = $block - (strlen($password) % $block); $password .= str_repeat(chr($padding), $padding); return mcrypt_encrypt($this->mcrypt_cipher, $key, $password, $this->mcrypt_mode, $iv); } } $foo = new Foo; $pass = 'p@ss'; $salt = 's@1t'; $key = PBKDF1($pass, $salt, 2, 32); $iv = "@1B2c3D4e5F6g7H8"; $encrypted = $foo->encrypt($key,$iv,'test@123'); $encrypted = base64_encode($encrypted); echo 'Encrypted: '.$encrypted.'</br>'; echo 'Decrypted: '.$foo->decrypt($key, $iv, $encrypted); function PBKDF1($pass, $salt, $count, $cb) { static $base; static $extra; static $extracount= 0; static $hashno; static $state = 0; if ($state == 0) { $hashno = 0; $state = 1; $key = $pass . $salt; $base = sha1($key, true); for($i = 2; $i < $count; $i++) { $base = sha1($base, true); } } $result = ""; if ($extracount > 0) { $rlen = strlen($extra) - $extracount; if ($rlen >= $cb) { $result = substr($extra, $extracount, $cb); if ($rlen > $cb) { $extracount += $cb; } else { $extra = null; $extracount = 0; } return $result; } $result = substr($extra, $rlen, $rlen); } $current = ""; $clen = 0; $remain = $cb - strlen($result); while ($remain > $clen) { if ($hashno == 0) { $current = sha1($base, true); } else if ($hashno < 1000) { $n = sprintf("%d", $hashno); $tmp = $n . $base; $current .= sha1($tmp, true); } $hashno++; $clen = strlen($current); } // $current now holds at least as many bytes as we need $result .= substr($current, 0, $remain); // Save any left over bytes for any future requests if ($clen > $remain) { $extra = $current; $extracount = $remain; } return $result; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Wh5Pp
function name:  (null)
number of ops:  34
compiled vars:  !0 = $foo, !1 = $pass, !2 = $salt, !3 = $key, !4 = $iv, !5 = $encrypted
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   NEW                                              $6      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $6
   20     3        ASSIGN                                                   !1, 'p%40ss'
   21     4        ASSIGN                                                   !2, 's%401t'
   23     5        INIT_FCALL_BY_NAME                                       'PBKDF1'
          6        SEND_VAR_EX                                              !1
          7        SEND_VAR_EX                                              !2
          8        SEND_VAL_EX                                              2
          9        SEND_VAL_EX                                              32
         10        DO_FCALL                                      0  $11     
         11        ASSIGN                                                   !3, $11
   25    12        ASSIGN                                                   !4, '%401B2c3D4e5F6g7H8'
   27    13        INIT_METHOD_CALL                                         !0, 'encrypt'
         14        SEND_VAR_EX                                              !3
         15        SEND_VAR_EX                                              !4
         16        SEND_VAL_EX                                              'test%40123'
         17        DO_FCALL                                      0  $14     
         18        ASSIGN                                                   !5, $14
   29    19        INIT_FCALL                                               'base64_encode'
         20        SEND_VAR                                                 !5
         21        DO_ICALL                                         $16     
         22        ASSIGN                                                   !5, $16
   31    23        CONCAT                                           ~18     'Encrypted%3A+', !5
         24        CONCAT                                           ~19     ~18, '%3C%2Fbr%3E'
         25        ECHO                                                     ~19
   32    26        INIT_METHOD_CALL                                         !0, 'decrypt'
         27        SEND_VAR_EX                                              !3
         28        SEND_VAR_EX                                              !4
         29        SEND_VAR_EX                                              !5
         30        DO_FCALL                                      0  $20     
         31        CONCAT                                           ~21     'Decrypted%3A+', $20
         32        ECHO                                                     ~21
  109    33      > RETURN                                                   1

Function pbkdf1:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 30
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 22
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 57
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 51
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 48
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 88
Branch analysis from position: 88
2 jumps found. (Code = 44) Position 1 = 90, Position 2 = 63
Branch analysis from position: 90
2 jumps found. (Code = 43) Position 1 = 98, Position 2 = 100
Branch analysis from position: 98
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 100
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 71
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 85
Branch analysis from position: 85
2 jumps found. (Code = 44) Position 1 = 90, Position 2 = 63
Branch analysis from position: 90
Branch analysis from position: 63
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 85
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 90, Position 2 = 63
Branch analysis from position: 90
Branch analysis from position: 63
Branch analysis from position: 85
Branch analysis from position: 57
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 22
Branch analysis from position: 30
Branch analysis from position: 22
Branch analysis from position: 30
filename:       /in/Wh5Pp
function name:  PBKDF1
number of ops:  102
compiled vars:  !0 = $pass, !1 = $salt, !2 = $count, !3 = $cb, !4 = $base, !5 = $extra, !6 = $extracount, !7 = $hashno, !8 = $state, !9 = $key, !10 = $i, !11 = $result, !12 = $rlen, !13 = $current, !14 = $clen, !15 = $remain, !16 = $n, !17 = $tmp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   38     4        BIND_STATIC                                              !4
   39     5        BIND_STATIC                                              !5
   40     6        BIND_STATIC                                              !6
   41     7        BIND_STATIC                                              !7
   42     8        BIND_STATIC                                              !8
   44     9        IS_EQUAL                                                 !8, 0
         10      > JMPZ                                                     ~18, ->30
   46    11    >   ASSIGN                                                   !7, 0
   47    12        ASSIGN                                                   !8, 1
   49    13        CONCAT                                           ~21     !0, !1
         14        ASSIGN                                                   !9, ~21
   50    15        INIT_FCALL                                               'sha1'
         16        SEND_VAR                                                 !9
         17        SEND_VAL                                                 <true>
         18        DO_ICALL                                         $23     
         19        ASSIGN                                                   !4, $23
   51    20        ASSIGN                                                   !10, 2
         21      > JMP                                                      ->28
   53    22    >   INIT_FCALL                                               'sha1'
         23        SEND_VAR                                                 !4
         24        SEND_VAL                                                 <true>
         25        DO_ICALL                                         $26     
         26        ASSIGN                                                   !4, $26
   51    27        PRE_INC                                                  !10
         28    >   IS_SMALLER                                               !10, !2
         29      > JMPNZ                                                    ~29, ->22
   57    30    >   ASSIGN                                                   !11, ''
   59    31        IS_SMALLER                                               0, !6
         32      > JMPZ                                                     ~31, ->57
   61    33    >   STRLEN                                           ~32     !5
         34        SUB                                              ~33     ~32, !6
         35        ASSIGN                                                   !12, ~33
   62    36        IS_SMALLER_OR_EQUAL                                      !3, !12
         37      > JMPZ                                                     ~35, ->51
   64    38    >   INIT_FCALL                                               'substr'
         39        SEND_VAR                                                 !5
         40        SEND_VAR                                                 !6
         41        SEND_VAR                                                 !3
         42        DO_ICALL                                         $36     
         43        ASSIGN                                                   !11, $36
   65    44        IS_SMALLER                                               !3, !12
         45      > JMPZ                                                     ~38, ->48
   67    46    >   ASSIGN_OP                                     1          !6, !3
         47      > JMP                                                      ->50
   71    48    >   ASSIGN                                                   !5, null
   72    49        ASSIGN                                                   !6, 0
   74    50    > > RETURN                                                   !11
   76    51    >   INIT_FCALL                                               'substr'
         52        SEND_VAR                                                 !5
         53        SEND_VAR                                                 !12
         54        SEND_VAR                                                 !12
         55        DO_ICALL                                         $42     
         56        ASSIGN                                                   !11, $42
   79    57    >   ASSIGN                                                   !13, ''
   80    58        ASSIGN                                                   !14, 0
   81    59        STRLEN                                           ~46     !11
         60        SUB                                              ~47     !3, ~46
         61        ASSIGN                                                   !15, ~47
   82    62      > JMP                                                      ->88
   84    63    >   IS_EQUAL                                                 !7, 0
         64      > JMPZ                                                     ~49, ->71
   86    65    >   INIT_FCALL                                               'sha1'
         66        SEND_VAR                                                 !4
         67        SEND_VAL                                                 <true>
         68        DO_ICALL                                         $50     
         69        ASSIGN                                                   !13, $50
         70      > JMP                                                      ->85
   88    71    >   IS_SMALLER                                               !7, 1000
         72      > JMPZ                                                     ~52, ->85
   90    73    >   INIT_FCALL                                               'sprintf'
         74        SEND_VAL                                                 '%25d'
         75        SEND_VAR                                                 !7
         76        DO_ICALL                                         $53     
         77        ASSIGN                                                   !16, $53
   91    78        CONCAT                                           ~55     !16, !4
         79        ASSIGN                                                   !17, ~55
   92    80        INIT_FCALL                                               'sha1'
         81        SEND_VAR                                                 !17
         82        SEND_VAL                                                 <true>
         83        DO_ICALL                                         $57     
         84        ASSIGN_OP                                     8          !13, $57
   94    85    >   PRE_INC                                                  !7
   95    86        STRLEN                                           ~60     !13
         87        ASSIGN                                                   !14, ~60
   82    88    >   IS_SMALLER                                               !14, !15
         89      > JMPNZ                                                    ~62, ->63
   99    90    >   INIT_FCALL                                               'substr'
         91        SEND_VAR                                                 !13
         92        SEND_VAL                                                 0
         93        SEND_VAR                                                 !15
         94        DO_ICALL                                         $63     
         95        ASSIGN_OP                                     8          !11, $63
  102    96        IS_SMALLER                                               !15, !14
         97      > JMPZ                                                     ~65, ->100
  104    98    >   ASSIGN                                                   !5, !13
  105    99        ASSIGN                                                   !6, !15
  108   100    > > RETURN                                                   !11
  109   101*     > RETURN                                                   null

End of function pbkdf1

Class Foo:
Function decrypt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Wh5Pp
function name:  decrypt
number of ops:  19
compiled vars:  !0 = $key, !1 = $iv, !2 = $encrypted
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    8     3        INIT_FCALL_BY_NAME                                       'mcrypt_decrypt'
          4        CHECK_FUNC_ARG                                           
          5        FETCH_OBJ_FUNC_ARG                               $3      'mcrypt_cipher'
          6        SEND_FUNC_ARG                                            $3
          7        SEND_VAR_EX                                              !0
          8        INIT_FCALL                                               'base64_decode'
          9        SEND_VAR                                                 !2
         10        DO_ICALL                                         $4      
         11        SEND_VAR_NO_REF_EX                                       $4
         12        CHECK_FUNC_ARG                                           
         13        FETCH_OBJ_FUNC_ARG                               $5      'mcrypt_mode'
         14        SEND_FUNC_ARG                                            $5
         15        SEND_VAR_EX                                              !1
         16        DO_FCALL                                      0  $6      
         17      > RETURN                                                   $6
    9    18*     > RETURN                                                   null

End of function decrypt

Function encrypt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Wh5Pp
function name:  encrypt
number of ops:  35
compiled vars:  !0 = $key, !1 = $iv, !2 = $password, !3 = $block, !4 = $padding
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   13     3        INIT_FCALL_BY_NAME                                       'mcrypt_get_block_size'
          4        FETCH_CONSTANT                                   ~5      'MCRYPT_RIJNDAEL_128'
          5        SEND_VAL_EX                                              ~5
          6        FETCH_CONSTANT                                   ~6      'MCRYPT_MODE_ECB'
          7        SEND_VAL_EX                                              ~6
          8        DO_FCALL                                      0  $7      
          9        ASSIGN                                                   !3, $7
   14    10        STRLEN                                           ~9      !2
         11        MOD                                              ~10     ~9, !3
         12        SUB                                              ~11     !3, ~10
         13        ASSIGN                                                   !4, ~11
   15    14        INIT_FCALL                                               'str_repeat'
         15        INIT_FCALL                                               'chr'
         16        SEND_VAR                                                 !4
         17        DO_ICALL                                         $13     
         18        SEND_VAR                                                 $13
         19        SEND_VAR                                                 !4
         20        DO_ICALL                                         $14     
         21        ASSIGN_OP                                     8          !2, $14
   16    22        INIT_FCALL_BY_NAME                                       'mcrypt_encrypt'
         23        CHECK_FUNC_ARG                                           
         24        FETCH_OBJ_FUNC_ARG                               $16     'mcrypt_cipher'
         25        SEND_FUNC_ARG                                            $16
         26        SEND_VAR_EX                                              !0
         27        SEND_VAR_EX                                              !2
         28        CHECK_FUNC_ARG                                           
         29        FETCH_OBJ_FUNC_ARG                               $17     'mcrypt_mode'
         30        SEND_FUNC_ARG                                            $17
         31        SEND_VAR_EX                                              !1
         32        DO_FCALL                                      0  $18     
         33      > RETURN                                                   $18
   17    34*     > RETURN                                                   null

End of function encrypt

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.44 ms | 1412 KiB | 27 Q