3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * MCrypt Library to enable encryption and decryption using MCrypt. * NOTE: this is an adjusted version of the below source. * SOURCE: https://raw.githubusercontent.com/serpro/Android-PHP-Encrypt-Decrypt/master/PHP/MCrypt.php */ class Mcrypt { /** * IV parameter */ private $iv = 'hoewhowhahwoahoe'; function __construct() { // empty } /** * @param string $str * @param bool $isBinary whether to encrypt as binary or not. Default is: false * @return string Encrypted data */ public function encrypt($str, $key, $isBinary = FALSE) { // variables $str = $isBinary ? $str : utf8_decode($str); $td = mcrypt_module_open('rijndael-128', ' ', 'cbc', $this->iv); // guard: check if the str is valid if (empty($str)) { return $str; } mcrypt_generic_init($td, $key, $this->iv); $encrypted = mcrypt_generic($td, $str); mcrypt_generic_deinit($td); mcrypt_module_close($td); return $isBinary ? $encrypted : base64_encode(bin2hex($encrypted)); } /** * @param string $code * @param bool $isBinary whether to decrypt as binary or not. Default is: false * @return string Decrypted data */ public function decrypt($code, $key, $isBinary = FALSE) { // variables $code = $isBinary ? $code : $this->hex2bin(base64_decode($code)); $td = mcrypt_module_open('rijndael-128', ' ', 'cbc', $this->iv); // guard: check if the code is valid if (empty($code)) { return $code; } mcrypt_generic_init($td, $key, $this->iv); $decrypted = mdecrypt_generic($td, $code); mcrypt_generic_deinit($td); mcrypt_module_close($td); return $isBinary ? trim($decrypted) : utf8_encode(trim($decrypted)); } protected function hex2bin($hexdata) { $bindata = ''; for ($i = 0; $i < strlen($hexdata); $i += 2) { $bindata .= chr(hexdec(substr($hexdata, $i, 2))); } return $bindata; } } $mcrypt = new Mcrypt(); $key = "8f1ec9b37ccd2e88aa4279999818d28d"; $string = "OGZkM2M2NGI4MWRlMzg1MzlmZDRiN2ZjODA1NTM1MDA="; echo($mcrypt->decrypt($string, $key));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QFBPr
function name:  (null)
number of ops:  11
compiled vars:  !0 = $mcrypt, !1 = $key, !2 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   86     0  E >   NEW                                              $3      'Mcrypt'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
   87     3        ASSIGN                                                   !1, '8f1ec9b37ccd2e88aa4279999818d28d'
   88     4        ASSIGN                                                   !2, 'OGZkM2M2NGI4MWRlMzg1MzlmZDRiN2ZjODA1NTM1MDA%3D'
   89     5        INIT_METHOD_CALL                                         !0, 'decrypt'
          6        SEND_VAR_EX                                              !2
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0  $8      
          9        ECHO                                                     $8
         10      > RETURN                                                   1

Class Mcrypt:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QFBPr
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E > > RETURN                                                   null

End of function __construct

Function encrypt:
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 = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
Branch analysis from position: 23
filename:       /in/QFBPr
function name:  encrypt
number of ops:  53
compiled vars:  !0 = $str, !1 = $key, !2 = $isBinary, !3 = $td, !4 = $encrypted
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <false>
   30     3      > JMPZ                                                     !2, ->6
          4    >   QM_ASSIGN                                        ~5      !0
          5      > JMP                                                      ->10
          6    >   INIT_FCALL                                               'utf8_decode'
          7        SEND_VAR                                                 !0
          8        DO_FCALL_BY_NAME                                         
          9        QM_ASSIGN                                        ~5      $6
         10    >   ASSIGN                                                   !0, ~5
   31    11        INIT_FCALL_BY_NAME                                       'mcrypt_module_open'
         12        SEND_VAL_EX                                              'rijndael-128'
         13        SEND_VAL_EX                                              '+'
         14        SEND_VAL_EX                                              'cbc'
         15        CHECK_FUNC_ARG                                           
         16        FETCH_OBJ_FUNC_ARG                               $8      'iv'
         17        SEND_FUNC_ARG                                            $8
         18        DO_FCALL                                      0  $9      
         19        ASSIGN                                                   !3, $9
   34    20        ISSET_ISEMPTY_CV                                         !0
         21      > JMPZ                                                     ~11, ->23
   35    22    > > RETURN                                                   !0
   38    23    >   INIT_FCALL_BY_NAME                                       'mcrypt_generic_init'
         24        SEND_VAR_EX                                              !3
         25        SEND_VAR_EX                                              !1
         26        CHECK_FUNC_ARG                                           
         27        FETCH_OBJ_FUNC_ARG                               $12     'iv'
         28        SEND_FUNC_ARG                                            $12
         29        DO_FCALL                                      0          
   39    30        INIT_FCALL_BY_NAME                                       'mcrypt_generic'
         31        SEND_VAR_EX                                              !3
         32        SEND_VAR_EX                                              !0
         33        DO_FCALL                                      0  $14     
         34        ASSIGN                                                   !4, $14
   41    35        INIT_FCALL_BY_NAME                                       'mcrypt_generic_deinit'
         36        SEND_VAR_EX                                              !3
         37        DO_FCALL                                      0          
   42    38        INIT_FCALL_BY_NAME                                       'mcrypt_module_close'
         39        SEND_VAR_EX                                              !3
         40        DO_FCALL                                      0          
   44    41      > JMPZ                                                     !2, ->44
         42    >   QM_ASSIGN                                        ~18     !4
         43      > JMP                                                      ->51
         44    >   INIT_FCALL                                               'base64_encode'
         45        INIT_FCALL                                               'bin2hex'
         46        SEND_VAR                                                 !4
         47        DO_ICALL                                         $19     
         48        SEND_VAR                                                 $19
         49        DO_ICALL                                         $20     
         50        QM_ASSIGN                                        ~18     $20
         51    > > RETURN                                                   ~18
   45    52*     > RETURN                                                   null

End of function encrypt

Function decrypt:
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 = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 26
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 50
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 26
Branch analysis from position: 25
Branch analysis from position: 26
filename:       /in/QFBPr
function name:  decrypt
number of ops:  59
compiled vars:  !0 = $code, !1 = $key, !2 = $isBinary, !3 = $td, !4 = $decrypted
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <false>
   56     3      > JMPZ                                                     !2, ->6
          4    >   QM_ASSIGN                                        ~5      !0
          5      > JMP                                                      ->13
          6    >   INIT_METHOD_CALL                                         'hex2bin'
          7        INIT_FCALL                                               'base64_decode'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $6      
         10        SEND_VAR_NO_REF_EX                                       $6
         11        DO_FCALL                                      0  $7      
         12        QM_ASSIGN                                        ~5      $7
         13    >   ASSIGN                                                   !0, ~5
   57    14        INIT_FCALL_BY_NAME                                       'mcrypt_module_open'
         15        SEND_VAL_EX                                              'rijndael-128'
         16        SEND_VAL_EX                                              '+'
         17        SEND_VAL_EX                                              'cbc'
         18        CHECK_FUNC_ARG                                           
         19        FETCH_OBJ_FUNC_ARG                               $9      'iv'
         20        SEND_FUNC_ARG                                            $9
         21        DO_FCALL                                      0  $10     
         22        ASSIGN                                                   !3, $10
   60    23        ISSET_ISEMPTY_CV                                         !0
         24      > JMPZ                                                     ~12, ->26
   61    25    > > RETURN                                                   !0
   64    26    >   INIT_FCALL_BY_NAME                                       'mcrypt_generic_init'
         27        SEND_VAR_EX                                              !3
         28        SEND_VAR_EX                                              !1
         29        CHECK_FUNC_ARG                                           
         30        FETCH_OBJ_FUNC_ARG                               $13     'iv'
         31        SEND_FUNC_ARG                                            $13
         32        DO_FCALL                                      0          
   65    33        INIT_FCALL_BY_NAME                                       'mdecrypt_generic'
         34        SEND_VAR_EX                                              !3
         35        SEND_VAR_EX                                              !0
         36        DO_FCALL                                      0  $15     
         37        ASSIGN                                                   !4, $15
   67    38        INIT_FCALL_BY_NAME                                       'mcrypt_generic_deinit'
         39        SEND_VAR_EX                                              !3
         40        DO_FCALL                                      0          
   68    41        INIT_FCALL_BY_NAME                                       'mcrypt_module_close'
         42        SEND_VAR_EX                                              !3
         43        DO_FCALL                                      0          
   70    44      > JMPZ                                                     !2, ->50
         45    >   INIT_FCALL                                               'trim'
         46        SEND_VAR                                                 !4
         47        DO_ICALL                                         $19     
         48        QM_ASSIGN                                        ~20     $19
         49      > JMP                                                      ->57
         50    >   INIT_FCALL                                               'utf8_encode'
         51        INIT_FCALL                                               'trim'
         52        SEND_VAR                                                 !4
         53        DO_ICALL                                         $21     
         54        SEND_VAR                                                 $21
         55        DO_FCALL_BY_NAME                                         
         56        QM_ASSIGN                                        ~20     $22
         57    > > RETURN                                                   ~20
   71    58*     > RETURN                                                   null

End of function decrypt

Function hex2bin:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 4
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 4
Branch analysis from position: 20
Branch analysis from position: 4
filename:       /in/QFBPr
function name:  hex2bin
number of ops:  22
compiled vars:  !0 = $hexdata, !1 = $bindata, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   73     0  E >   RECV                                             !0      
   75     1        ASSIGN                                                   !1, ''
   77     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->17
   78     4    >   INIT_FCALL                                               'chr'
          5        INIT_FCALL                                               'hexdec'
          6        INIT_FCALL                                               'substr'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !2
          9        SEND_VAL                                                 2
         10        DO_ICALL                                         $5      
         11        SEND_VAR                                                 $5
         12        DO_ICALL                                         $6      
         13        SEND_VAR                                                 $6
         14        DO_ICALL                                         $7      
         15        ASSIGN_OP                                     8          !1, $7
   77    16        ASSIGN_OP                                     1          !2, 2
         17    >   STRLEN                                           ~10     !0
         18        IS_SMALLER                                               !2, ~10
         19      > JMPNZ                                                    ~11, ->4
   81    20    > > RETURN                                                   !1
   82    21*     > RETURN                                                   null

End of function hex2bin

End of class Mcrypt.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.24 ms | 1032 KiB | 22 Q