3v4l.org

run code in 300+ PHP versions simultaneously
<?php function encrypt($decrypted, $password, $salt='123456789') { $key = hash('SHA256', $salt . $password, true); srand(); $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND); if (strlen($iv_base64 = rtrim(base64_encode($iv), '=')) != 22) return false; $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $decrypted . md5($decrypted), MCRYPT_MODE_CBC, $iv)); return $iv_base64 . $encrypted; } function decrypt($encrypted, $password, $salt='123456789') { $key = hash('SHA256', $salt . $password, true); $iv = base64_decode(substr($encrypted, 0, 22) . '=='); $encrypted = substr($encrypted, 22); $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($encrypted), MCRYPT_MODE_CBC, $iv), "\0\4"); $hash = substr($decrypted, -32); $decrypted = substr($decrypted, 0, -32); if (md5($decrypted) != $hash) return false; return $decrypted; } print_r (encrypt(" mi texto","asdf")); echo "\n"; print_r ("= " + decrypt(encrypt(" mi texto","asdf"),"asdf")); echo "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kGfSq
function name:  (null)
number of ops:  22
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   INIT_FCALL                                               'print_r'
          1        INIT_FCALL                                               'encrypt'
          2        SEND_VAL                                                 '+mi+texto'
          3        SEND_VAL                                                 'asdf'
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
   25     7        ECHO                                                     '%0A'
   26     8        INIT_FCALL                                               'print_r'
          9        INIT_FCALL                                               'decrypt'
         10        INIT_FCALL                                               'encrypt'
         11        SEND_VAL                                                 '+mi+texto'
         12        SEND_VAL                                                 'asdf'
         13        DO_FCALL                                      0  $2      
         14        SEND_VAR                                                 $2
         15        SEND_VAL                                                 'asdf'
         16        DO_FCALL                                      0  $3      
         17        ADD                                              ~4      '%3D+', $3
         18        SEND_VAL                                                 ~4
         19        DO_ICALL                                                 
   27    20        ECHO                                                     '%0A'
         21      > RETURN                                                   1

Function encrypt:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 36
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kGfSq
function name:  encrypt
number of ops:  56
compiled vars:  !0 = $decrypted, !1 = $password, !2 = $salt, !3 = $key, !4 = $iv, !5 = $iv_base64, !6 = $encrypted
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      '123456789'
    4     3        INIT_FCALL                                               'hash'
          4        SEND_VAL                                                 'SHA256'
          5        CONCAT                                           ~7      !2, !1
          6        SEND_VAL                                                 ~7
          7        SEND_VAL                                                 <true>
          8        DO_ICALL                                         $8      
          9        ASSIGN                                                   !3, $8
    5    10        INIT_FCALL                                               'srand'
         11        DO_ICALL                                                 
         12        INIT_FCALL_BY_NAME                                       'mcrypt_create_iv'
         13        INIT_FCALL_BY_NAME                                       'mcrypt_get_iv_size'
         14        FETCH_CONSTANT                                   ~11     'MCRYPT_RIJNDAEL_128'
         15        SEND_VAL_EX                                              ~11
         16        FETCH_CONSTANT                                   ~12     'MCRYPT_MODE_CBC'
         17        SEND_VAL_EX                                              ~12
         18        DO_FCALL                                      0  $13     
         19        SEND_VAR_NO_REF_EX                                       $13
         20        FETCH_CONSTANT                                   ~14     'MCRYPT_RAND'
         21        SEND_VAL_EX                                              ~14
         22        DO_FCALL                                      0  $15     
         23        ASSIGN                                                   !4, $15
    6    24        INIT_FCALL                                               'rtrim'
         25        INIT_FCALL                                               'base64_encode'
         26        SEND_VAR                                                 !4
         27        DO_ICALL                                         $17     
         28        SEND_VAR                                                 $17
         29        SEND_VAL                                                 '%3D'
         30        DO_ICALL                                         $18     
         31        ASSIGN                                           ~19     !5, $18
         32        STRLEN                                           ~20     ~19
         33        IS_NOT_EQUAL                                             ~20, 22
         34      > JMPZ                                                     ~21, ->36
         35    > > RETURN                                                   <false>
    7    36    >   INIT_FCALL                                               'base64_encode'
         37        INIT_FCALL_BY_NAME                                       'mcrypt_encrypt'
         38        FETCH_CONSTANT                                   ~22     'MCRYPT_RIJNDAEL_128'
         39        SEND_VAL_EX                                              ~22
         40        SEND_VAR_EX                                              !3
         41        INIT_FCALL                                               'md5'
         42        SEND_VAR                                                 !0
         43        DO_ICALL                                         $23     
         44        CONCAT                                           ~24     !0, $23
         45        SEND_VAL_EX                                              ~24
         46        FETCH_CONSTANT                                   ~25     'MCRYPT_MODE_CBC'
         47        SEND_VAL_EX                                              ~25
         48        SEND_VAR_EX                                              !4
         49        DO_FCALL                                      0  $26     
         50        SEND_VAR                                                 $26
         51        DO_ICALL                                         $27     
         52        ASSIGN                                                   !6, $27
    9    53        CONCAT                                           ~29     !5, !6
         54      > RETURN                                                   ~29
   10    55*     > RETURN                                                   null

End of function encrypt

Function decrypt:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 59
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kGfSq
function name:  decrypt
number of ops:  61
compiled vars:  !0 = $encrypted, !1 = $password, !2 = $salt, !3 = $key, !4 = $iv, !5 = $decrypted, !6 = $hash
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      '123456789'
   13     3        INIT_FCALL                                               'hash'
          4        SEND_VAL                                                 'SHA256'
          5        CONCAT                                           ~7      !2, !1
          6        SEND_VAL                                                 ~7
          7        SEND_VAL                                                 <true>
          8        DO_ICALL                                         $8      
          9        ASSIGN                                                   !3, $8
   14    10        INIT_FCALL                                               'base64_decode'
         11        INIT_FCALL                                               'substr'
         12        SEND_VAR                                                 !0
         13        SEND_VAL                                                 0
         14        SEND_VAL                                                 22
         15        DO_ICALL                                         $10     
         16        CONCAT                                           ~11     $10, '%3D%3D'
         17        SEND_VAL                                                 ~11
         18        DO_ICALL                                         $12     
         19        ASSIGN                                                   !4, $12
   15    20        INIT_FCALL                                               'substr'
         21        SEND_VAR                                                 !0
         22        SEND_VAL                                                 22
         23        DO_ICALL                                         $14     
         24        ASSIGN                                                   !0, $14
   16    25        INIT_FCALL                                               'rtrim'
         26        INIT_FCALL_BY_NAME                                       'mcrypt_decrypt'
         27        FETCH_CONSTANT                                   ~16     'MCRYPT_RIJNDAEL_128'
         28        SEND_VAL_EX                                              ~16
         29        SEND_VAR_EX                                              !3
         30        INIT_FCALL                                               'base64_decode'
         31        SEND_VAR                                                 !0
         32        DO_ICALL                                         $17     
         33        SEND_VAR_NO_REF_EX                                       $17
         34        FETCH_CONSTANT                                   ~18     'MCRYPT_MODE_CBC'
         35        SEND_VAL_EX                                              ~18
         36        SEND_VAR_EX                                              !4
         37        DO_FCALL                                      0  $19     
         38        SEND_VAR                                                 $19
         39        SEND_VAL                                                 '%00%04'
         40        DO_ICALL                                         $20     
         41        ASSIGN                                                   !5, $20
   17    42        INIT_FCALL                                               'substr'
         43        SEND_VAR                                                 !5
         44        SEND_VAL                                                 -32
         45        DO_ICALL                                         $22     
         46        ASSIGN                                                   !6, $22
   18    47        INIT_FCALL                                               'substr'
         48        SEND_VAR                                                 !5
         49        SEND_VAL                                                 0
         50        SEND_VAL                                                 -32
         51        DO_ICALL                                         $24     
         52        ASSIGN                                                   !5, $24
   19    53        INIT_FCALL                                               'md5'
         54        SEND_VAR                                                 !5
         55        DO_ICALL                                         $26     
         56        IS_NOT_EQUAL                                             !6, $26
         57      > JMPZ                                                     ~27, ->59
         58    > > RETURN                                                   <false>
   21    59    > > RETURN                                                   !5
   22    60*     > RETURN                                                   null

End of function decrypt

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.07 ms | 1033 KiB | 24 Q