3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "secret"; function getKey($seed='no seed??') { return hash('sha256', $seed, 1); } function encrypt($key, $string) { $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); $iv = mcrypt_create_iv($size, MCRYPT_RAND); $encrypted_string = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_CBC, $iv); return base64_encode($iv . $encrypted_string); } function decrypt($key, $encoded_string) { $binary = base64_decode($encoded_string); $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); $iv = substr($binary, 0, $size); $encrypted_string = substr($binary, $size); return mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $encrypted_string, MCRYPT_MODE_CBC, $iv); } $key = getKey('Some Secret String'); $encrypted = encrypt($key, 'This is a string that will be encrypted'); echo decrypt($key, $encrypted);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/diXEM
function name:  (null)
number of ops:  16
compiled vars:  !0 = $string, !1 = $key, !2 = $encrypted
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'secret'
   25     1        INIT_FCALL                                               'getkey'
          2        SEND_VAL                                                 'Some+Secret+String'
          3        DO_FCALL                                      0  $4      
          4        ASSIGN                                                   !1, $4
   26     5        INIT_FCALL                                               'encrypt'
          6        SEND_VAR                                                 !1
          7        SEND_VAL                                                 'This+is+a+string+that+will+be+encrypted'
          8        DO_FCALL                                      0  $6      
          9        ASSIGN                                                   !2, $6
   27    10        INIT_FCALL                                               'decrypt'
         11        SEND_VAR                                                 !1
         12        SEND_VAR                                                 !2
         13        DO_FCALL                                      0  $8      
         14        ECHO                                                     $8
         15      > RETURN                                                   1

Function getkey:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/diXEM
function name:  getKey
number of ops:  8
compiled vars:  !0 = $seed
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV_INIT                                        !0      'no+seed%3F%3F'
    5     1        INIT_FCALL                                               'hash'
          2        SEND_VAL                                                 'sha256'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 1
          5        DO_ICALL                                         $1      
          6      > RETURN                                                   $1
    6     7*     > RETURN                                                   null

End of function getkey

Function encrypt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/diXEM
function name:  encrypt
number of ops:  31
compiled vars:  !0 = $key, !1 = $string, !2 = $size, !3 = $iv, !4 = $encrypted_string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        INIT_FCALL_BY_NAME                                       'mcrypt_get_iv_size'
          3        FETCH_CONSTANT                                   ~5      'MCRYPT_RIJNDAEL_256'
          4        SEND_VAL_EX                                              ~5
          5        FETCH_CONSTANT                                   ~6      'MCRYPT_MODE_CBC'
          6        SEND_VAL_EX                                              ~6
          7        DO_FCALL                                      0  $7      
          8        ASSIGN                                                   !2, $7
   10     9        INIT_FCALL_BY_NAME                                       'mcrypt_create_iv'
         10        SEND_VAR_EX                                              !2
         11        FETCH_CONSTANT                                   ~9      'MCRYPT_RAND'
         12        SEND_VAL_EX                                              ~9
         13        DO_FCALL                                      0  $10     
         14        ASSIGN                                                   !3, $10
   11    15        INIT_FCALL_BY_NAME                                       'mcrypt_encrypt'
         16        FETCH_CONSTANT                                   ~12     'MCRYPT_RIJNDAEL_256'
         17        SEND_VAL_EX                                              ~12
         18        SEND_VAR_EX                                              !0
         19        SEND_VAR_EX                                              !1
         20        FETCH_CONSTANT                                   ~13     'MCRYPT_MODE_CBC'
         21        SEND_VAL_EX                                              ~13
         22        SEND_VAR_EX                                              !3
         23        DO_FCALL                                      0  $14     
         24        ASSIGN                                                   !4, $14
   12    25        INIT_FCALL                                               'base64_encode'
         26        CONCAT                                           ~16     !3, !4
         27        SEND_VAL                                                 ~16
         28        DO_ICALL                                         $17     
         29      > RETURN                                                   $17
   13    30*     > RETURN                                                   null

End of function encrypt

Function decrypt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/diXEM
function name:  decrypt
number of ops:  35
compiled vars:  !0 = $key, !1 = $encoded_string, !2 = $binary, !3 = $size, !4 = $iv, !5 = $encrypted_string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   16     2        INIT_FCALL                                               'base64_decode'
          3        SEND_VAR                                                 !1
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !2, $6
   17     6        INIT_FCALL_BY_NAME                                       'mcrypt_get_iv_size'
          7        FETCH_CONSTANT                                   ~8      'MCRYPT_RIJNDAEL_256'
          8        SEND_VAL_EX                                              ~8
          9        FETCH_CONSTANT                                   ~9      'MCRYPT_MODE_CBC'
         10        SEND_VAL_EX                                              ~9
         11        DO_FCALL                                      0  $10     
         12        ASSIGN                                                   !3, $10
   19    13        INIT_FCALL                                               'substr'
         14        SEND_VAR                                                 !2
         15        SEND_VAL                                                 0
         16        SEND_VAR                                                 !3
         17        DO_ICALL                                         $12     
         18        ASSIGN                                                   !4, $12
   20    19        INIT_FCALL                                               'substr'
         20        SEND_VAR                                                 !2
         21        SEND_VAR                                                 !3
         22        DO_ICALL                                         $14     
         23        ASSIGN                                                   !5, $14
   22    24        INIT_FCALL_BY_NAME                                       'mcrypt_decrypt'
         25        FETCH_CONSTANT                                   ~16     'MCRYPT_RIJNDAEL_256'
         26        SEND_VAL_EX                                              ~16
         27        SEND_VAR_EX                                              !0
         28        SEND_VAR_EX                                              !5
         29        FETCH_CONSTANT                                   ~17     'MCRYPT_MODE_CBC'
         30        SEND_VAL_EX                                              ~17
         31        SEND_VAR_EX                                              !4
         32        DO_FCALL                                      0  $18     
         33      > RETURN                                                   $18
   23    34*     > RETURN                                                   null

End of function decrypt

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.44 ms | 1407 KiB | 24 Q