3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Security { public static function encrypt($input, $key) { $size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); $input = Security::pkcs5_pad($input, $size); $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, ''); $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND); mcrypt_generic_init($td, $key, $iv); $data = mcrypt_generic($td, $input); mcrypt_generic_deinit($td); mcrypt_module_close($td); $data = base64_encode($data); return $data; } private static function pkcs5_pad ($text, $blocksize) { $pad = $blocksize - (strlen($text) % $blocksize); return $text . str_repeat(chr($pad), $pad); } public static function decrypt($sStr, $sKey) { $decrypted= mcrypt_decrypt( MCRYPT_RIJNDAEL_128, $sKey, base64_decode($sStr), MCRYPT_MODE_ECB ); $dec_s = strlen($decrypted); $padding = ord($decrypted[$dec_s-1]); $decrypted = substr($decrypted, 0, -$padding); return $decrypted; } } $value = "a"; $key = "KluczSzyfrujacyI"; //16 Character Key echo Security::encrypt($value, $key); echo Security::decrypt(Security::encrypt($value, $key), $key); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/72PWu
function name:  (null)
number of ops:  17
compiled vars:  !0 = $value, !1 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   ASSIGN                                                   !0, 'a'
   34     1        ASSIGN                                                   !1, 'KluczSzyfrujacyI'
   35     2        INIT_STATIC_METHOD_CALL                                  'Security', 'encrypt'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $4      
          6        ECHO                                                     $4
   36     7        INIT_STATIC_METHOD_CALL                                  'Security', 'decrypt'
          8        INIT_STATIC_METHOD_CALL                                  'Security', 'encrypt'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !1
         11        DO_FCALL                                      0  $5      
         12        SEND_VAR                                                 $5
         13        SEND_VAR                                                 !1
         14        DO_FCALL                                      0  $6      
         15        ECHO                                                     $6
   38    16      > RETURN                                                   1

Class Security:
Function encrypt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/72PWu
function name:  encrypt
number of ops:  54
compiled vars:  !0 = $input, !1 = $key, !2 = $size, !3 = $td, !4 = $iv, !5 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        INIT_FCALL_BY_NAME                                       'mcrypt_get_block_size'
          3        FETCH_CONSTANT                                   ~6      'MCRYPT_RIJNDAEL_128'
          4        SEND_VAL_EX                                              ~6
          5        FETCH_CONSTANT                                   ~7      'MCRYPT_MODE_ECB'
          6        SEND_VAL_EX                                              ~7
          7        DO_FCALL                                      0  $8      
          8        ASSIGN                                                   !2, $8
    5     9        INIT_STATIC_METHOD_CALL                                  'Security', 'pkcs5_pad'
         10        SEND_VAR_EX                                              !0
         11        SEND_VAR_EX                                              !2
         12        DO_FCALL                                      0  $10     
         13        ASSIGN                                                   !0, $10
    6    14        INIT_FCALL_BY_NAME                                       'mcrypt_module_open'
         15        FETCH_CONSTANT                                   ~12     'MCRYPT_RIJNDAEL_128'
         16        SEND_VAL_EX                                              ~12
         17        SEND_VAL_EX                                              ''
         18        FETCH_CONSTANT                                   ~13     'MCRYPT_MODE_ECB'
         19        SEND_VAL_EX                                              ~13
         20        SEND_VAL_EX                                              ''
         21        DO_FCALL                                      0  $14     
         22        ASSIGN                                                   !3, $14
    7    23        INIT_FCALL_BY_NAME                                       'mcrypt_create_iv'
         24        INIT_FCALL_BY_NAME                                       'mcrypt_enc_get_iv_size'
         25        SEND_VAR_EX                                              !3
         26        DO_FCALL                                      0  $16     
         27        SEND_VAR_NO_REF_EX                                       $16
         28        FETCH_CONSTANT                                   ~17     'MCRYPT_RAND'
         29        SEND_VAL_EX                                              ~17
         30        DO_FCALL                                      0  $18     
         31        ASSIGN                                                   !4, $18
    8    32        INIT_FCALL_BY_NAME                                       'mcrypt_generic_init'
         33        SEND_VAR_EX                                              !3
         34        SEND_VAR_EX                                              !1
         35        SEND_VAR_EX                                              !4
         36        DO_FCALL                                      0          
    9    37        INIT_FCALL_BY_NAME                                       'mcrypt_generic'
         38        SEND_VAR_EX                                              !3
         39        SEND_VAR_EX                                              !0
         40        DO_FCALL                                      0  $21     
         41        ASSIGN                                                   !5, $21
   10    42        INIT_FCALL_BY_NAME                                       'mcrypt_generic_deinit'
         43        SEND_VAR_EX                                              !3
         44        DO_FCALL                                      0          
   11    45        INIT_FCALL_BY_NAME                                       'mcrypt_module_close'
         46        SEND_VAR_EX                                              !3
         47        DO_FCALL                                      0          
   12    48        INIT_FCALL                                               'base64_encode'
         49        SEND_VAR                                                 !5
         50        DO_ICALL                                         $25     
         51        ASSIGN                                                   !5, $25
   13    52      > RETURN                                                   !5
   14    53*     > RETURN                                                   null

End of function encrypt

Function pkcs5_pad:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/72PWu
function name:  pkcs5_pad
number of ops:  16
compiled vars:  !0 = $text, !1 = $blocksize, !2 = $pad
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   16     2        STRLEN                                           ~3      !0
          3        MOD                                              ~4      ~3, !1
          4        SUB                                              ~5      !1, ~4
          5        ASSIGN                                                   !2, ~5
   17     6        INIT_FCALL                                               'str_repeat'
          7        INIT_FCALL                                               'chr'
          8        SEND_VAR                                                 !2
          9        DO_ICALL                                         $7      
         10        SEND_VAR                                                 $7
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                         $8      
         13        CONCAT                                           ~9      !0, $8
         14      > RETURN                                                   ~9
   18    15*     > RETURN                                                   null

End of function pkcs5_pad

Function decrypt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/72PWu
function name:  decrypt
number of ops:  31
compiled vars:  !0 = $sStr, !1 = $sKey, !2 = $decrypted, !3 = $dec_s, !4 = $padding
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   20     2        INIT_FCALL_BY_NAME                                       'mcrypt_decrypt'
   21     3        FETCH_CONSTANT                                   ~5      'MCRYPT_RIJNDAEL_128'
          4        SEND_VAL_EX                                              ~5
          5        SEND_VAR_EX                                              !1
   23     6        INIT_FCALL                                               'base64_decode'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $6      
          9        SEND_VAR_NO_REF_EX                                       $6
   24    10        FETCH_CONSTANT                                   ~7      'MCRYPT_MODE_ECB'
         11        SEND_VAL_EX                                              ~7
         12        DO_FCALL                                      0  $8      
   20    13        ASSIGN                                                   !2, $8
   26    14        STRLEN                                           ~10     !2
         15        ASSIGN                                                   !3, ~10
   27    16        INIT_FCALL                                               'ord'
         17        SUB                                              ~12     !3, 1
         18        FETCH_DIM_R                                      ~13     !2, ~12
         19        SEND_VAL                                                 ~13
         20        DO_ICALL                                         $14     
         21        ASSIGN                                                   !4, $14
   28    22        INIT_FCALL                                               'substr'
         23        SEND_VAR                                                 !2
         24        SEND_VAL                                                 0
         25        MUL                                              ~16     !4, -1
         26        SEND_VAL                                                 ~16
         27        DO_ICALL                                         $17     
         28        ASSIGN                                                   !2, $17
   29    29      > RETURN                                                   !2
   30    30*     > RETURN                                                   null

End of function decrypt

End of class Security.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.2 ms | 1404 KiB | 25 Q