3v4l.org

run code in 300+ PHP versions simultaneously
<?php function encrypt_decrypt($action, $string) { $output = false; $encrypt_method = "AES-256-CBC"; $secret_key = 'This is my secret key'; $secret_iv = 'This is my secret iv'; // hash $key = hash('sha256', $secret_key); // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning $iv = substr(hash('sha256', $secret_iv), 0, 16); if( $action == 'encrypt' ) { $output = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaintext, MCRYPT_MODE_CBC, $iv); $output = base64_encode($output); } else if( $action == 'decrypt' ){ $output = mcrypt_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv); } return $output; } $plain_txt = "This is my plain text"; echo "Plain Text = $plain_txt\n"; $encrypted_txt = encrypt_decrypt('encrypt', $plain_txt); echo "Encrypted Text = $encrypted_txt\n"; $decrypted_txt = encrypt_decrypt('decrypt', $encrypted_txt); echo "Decrypted Text = $decrypted_txt\n"; if( $plain_txt === $decrypted_txt ) echo "SUCCESS"; else echo "FAILED"; echo "\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eMCvj
function name:  (null)
number of ops:  30
compiled vars:  !0 = $plain_txt, !1 = $encrypted_txt, !2 = $decrypted_txt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   ASSIGN                                                   !0, 'This+is+my+plain+text'
   29     1        ROPE_INIT                                     3  ~5      'Plain+Text+%3D+'
          2        ROPE_ADD                                      1  ~5      ~5, !0
          3        ROPE_END                                      2  ~4      ~5, '%0A'
          4        ECHO                                                     ~4
   31     5        INIT_FCALL                                               'encrypt_decrypt'
          6        SEND_VAL                                                 'encrypt'
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0  $7      
          9        ASSIGN                                                   !1, $7
   32    10        ROPE_INIT                                     3  ~10     'Encrypted+Text+%3D+'
         11        ROPE_ADD                                      1  ~10     ~10, !1
         12        ROPE_END                                      2  ~9      ~10, '%0A'
         13        ECHO                                                     ~9
   34    14        INIT_FCALL                                               'encrypt_decrypt'
         15        SEND_VAL                                                 'decrypt'
         16        SEND_VAR                                                 !1
         17        DO_FCALL                                      0  $12     
         18        ASSIGN                                                   !2, $12
   35    19        ROPE_INIT                                     3  ~15     'Decrypted+Text+%3D+'
         20        ROPE_ADD                                      1  ~15     ~15, !2
         21        ROPE_END                                      2  ~14     ~15, '%0A'
         22        ECHO                                                     ~14
   37    23        IS_IDENTICAL                                             !0, !2
         24      > JMPZ                                                     ~17, ->27
         25    >   ECHO                                                     'SUCCESS'
         26      > JMP                                                      ->28
   38    27    >   ECHO                                                     'FAILED'
   40    28    >   ECHO                                                     '%0A'
         29      > RETURN                                                   1

Function encrypt_decrypt:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 38
Branch analysis from position: 23
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: 38
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 51
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
filename:       /in/eMCvj
function name:  encrypt_decrypt
number of ops:  53
compiled vars:  !0 = $action, !1 = $string, !2 = $output, !3 = $encrypt_method, !4 = $secret_key, !5 = $secret_iv, !6 = $key, !7 = $iv, !8 = $plaintext
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <false>
    6     3        ASSIGN                                                   !3, 'AES-256-CBC'
    7     4        ASSIGN                                                   !4, 'This+is+my+secret+key'
    8     5        ASSIGN                                                   !5, 'This+is+my+secret+iv'
   11     6        INIT_FCALL                                               'hash'
          7        SEND_VAL                                                 'sha256'
          8        SEND_VAR                                                 !4
          9        DO_ICALL                                         $13     
         10        ASSIGN                                                   !6, $13
   14    11        INIT_FCALL                                               'substr'
         12        INIT_FCALL                                               'hash'
         13        SEND_VAL                                                 'sha256'
         14        SEND_VAR                                                 !5
         15        DO_ICALL                                         $15     
         16        SEND_VAR                                                 $15
         17        SEND_VAL                                                 0
         18        SEND_VAL                                                 16
         19        DO_ICALL                                         $16     
         20        ASSIGN                                                   !7, $16
   16    21        IS_EQUAL                                                 !0, 'encrypt'
         22      > JMPZ                                                     ~18, ->38
   17    23    >   INIT_FCALL_BY_NAME                                       'mcrypt_encrypt'
         24        FETCH_CONSTANT                                   ~19     'MCRYPT_RIJNDAEL_128'
         25        SEND_VAL_EX                                              ~19
         26        SEND_VAR_EX                                              !6
         27        SEND_VAR_EX                                              !8
   18    28        FETCH_CONSTANT                                   ~20     'MCRYPT_MODE_CBC'
         29        SEND_VAL_EX                                              ~20
   17    30        SEND_VAR_EX                                              !7
         31        DO_FCALL                                      0  $21     
         32        ASSIGN                                                   !2, $21
   19    33        INIT_FCALL                                               'base64_encode'
         34        SEND_VAR                                                 !2
         35        DO_ICALL                                         $23     
         36        ASSIGN                                                   !2, $23
         37      > JMP                                                      ->51
   21    38    >   IS_EQUAL                                                 !0, 'decrypt'
         39      > JMPZ                                                     ~25, ->51
   22    40    >   INIT_FCALL_BY_NAME                                       'mcrypt_decrypt'
         41        INIT_FCALL                                               'base64_decode'
         42        SEND_VAR                                                 !1
         43        DO_ICALL                                         $26     
         44        SEND_VAR_NO_REF_EX                                       $26
         45        SEND_VAR_EX                                              !3
         46        SEND_VAR_EX                                              !6
         47        SEND_VAL_EX                                              0
         48        SEND_VAR_EX                                              !7
         49        DO_FCALL                                      0  $27     
         50        ASSIGN                                                   !2, $27
   25    51    > > RETURN                                                   !2
   26    52*     > RETURN                                                   null

End of function encrypt_decrypt

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.87 ms | 1406 KiB | 23 Q