3v4l.org

run code in 300+ PHP versions simultaneously
<?php $algo = 'aes-256-gcm'; $iv = random_bytes(openssl_cipher_iv_length($algo)); $key = random_bytes(32); // 256 bit //$data = random_bytes(1024); // 1 Kb of random data $data = "well hello there"; $ciphertext = openssl_encrypt( $data, $algo, $key, OPENSSL_RAW_DATA, $iv, $tag ); // Change 1 bit in ciphertext // $i = rand(0, mb_strlen($ciphertext, '8bit') - 1); // $ciphertext[$i] = $ciphertext[$i] ^ chr(1); echo(base64_encode($ciphertext)); echo("\n"); echo(base64_encode($tag)); $i = rand(0, mb_strlen($tag, '8bit') - 1); $tag[$i] = $tag[$i] ^ chr(1); echo("\n"); echo(base64_encode($tag)); $decrypt = openssl_decrypt( $ciphertext, $algo, $key, OPENSSL_RAW_DATA, $iv, $tag ); if (false === $decrypt) { throw new Exception(sprintf( "OpenSSL error: %s", openssl_error_string() )); } printf ("Decryption %s\n", $data === $decrypt ? 'Ok' : 'Failed');
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 73
Branch analysis from position: 63
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 73
2 jumps found. (Code = 43) Position 1 = 77, Position 2 = 79
Branch analysis from position: 77
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 79
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Z6jTA
function name:  (null)
number of ops:  83
compiled vars:  !0 = $algo, !1 = $iv, !2 = $key, !3 = $data, !4 = $ciphertext, !5 = $tag, !6 = $i, !7 = $decrypt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'aes-256-gcm'
    3     1        INIT_FCALL                                               'random_bytes'
          2        INIT_FCALL_BY_NAME                                       'openssl_cipher_iv_length'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $9      
          5        SEND_VAR                                                 $9
          6        DO_ICALL                                         $10     
          7        ASSIGN                                                   !1, $10
    4     8        INIT_FCALL                                               'random_bytes'
          9        SEND_VAL                                                 32
         10        DO_ICALL                                         $12     
         11        ASSIGN                                                   !2, $12
    6    12        ASSIGN                                                   !3, 'well+hello+there'
    7    13        INIT_FCALL_BY_NAME                                       'openssl_encrypt'
    8    14        SEND_VAR_EX                                              !3
         15        SEND_VAR_EX                                              !0
         16        SEND_VAR_EX                                              !2
   11    17        FETCH_CONSTANT                                   ~15     'OPENSSL_RAW_DATA'
         18        SEND_VAL_EX                                              ~15
    8    19        SEND_VAR_EX                                              !1
         20        SEND_VAR_EX                                              !5
         21        DO_FCALL                                      0  $16     
    7    22        ASSIGN                                                   !4, $16
   18    23        INIT_FCALL                                               'base64_encode'
         24        SEND_VAR                                                 !4
         25        DO_ICALL                                         $18     
         26        ECHO                                                     $18
   19    27        ECHO                                                     '%0A'
   20    28        INIT_FCALL                                               'base64_encode'
         29        SEND_VAR                                                 !5
         30        DO_ICALL                                         $19     
         31        ECHO                                                     $19
   21    32        INIT_FCALL                                               'rand'
         33        SEND_VAL                                                 0
         34        INIT_FCALL                                               'mb_strlen'
         35        SEND_VAR                                                 !5
         36        SEND_VAL                                                 '8bit'
         37        DO_ICALL                                         $20     
         38        SUB                                              ~21     $20, 1
         39        SEND_VAL                                                 ~21
         40        DO_ICALL                                         $22     
         41        ASSIGN                                                   !6, $22
   22    42        FETCH_DIM_R                                      ~25     !5, !6
         43        BW_XOR                                           ~26     ~25, '%01'
         44        ASSIGN_DIM                                               !5, !6
         45        OP_DATA                                                  ~26
   23    46        ECHO                                                     '%0A'
   24    47        INIT_FCALL                                               'base64_encode'
         48        SEND_VAR                                                 !5
         49        DO_ICALL                                         $27     
         50        ECHO                                                     $27
   25    51        INIT_FCALL_BY_NAME                                       'openssl_decrypt'
   26    52        SEND_VAR_EX                                              !4
         53        SEND_VAR_EX                                              !0
         54        SEND_VAR_EX                                              !2
   29    55        FETCH_CONSTANT                                   ~28     'OPENSSL_RAW_DATA'
         56        SEND_VAL_EX                                              ~28
   26    57        SEND_VAR_EX                                              !1
         58        SEND_VAR_EX                                              !5
         59        DO_FCALL                                      0  $29     
   25    60        ASSIGN                                                   !7, $29
   33    61        TYPE_CHECK                                    4          !7
         62      > JMPZ                                                     ~31, ->73
   34    63    >   NEW                                              $32     'Exception'
         64        INIT_FCALL                                               'sprintf'
   35    65        SEND_VAL                                                 'OpenSSL+error%3A+%25s'
         66        INIT_FCALL_BY_NAME                                       'openssl_error_string'
         67        DO_FCALL                                      0  $33     
         68        SEND_VAR                                                 $33
         69        DO_ICALL                                         $34     
         70        SEND_VAR_NO_REF_EX                                       $34
         71        DO_FCALL                                      0          
         72      > THROW                                         0          $32
   38    73    >   INIT_FCALL                                               'printf'
         74        SEND_VAL                                                 'Decryption+%25s%0A'
         75        IS_IDENTICAL                                             !3, !7
         76      > JMPZ                                                     ~36, ->79
         77    >   QM_ASSIGN                                        ~37     'Ok'
         78      > JMP                                                      ->80
         79    >   QM_ASSIGN                                        ~37     'Failed'
         80    >   SEND_VAL                                                 ~37
         81        DO_ICALL                                                 
         82      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.39 ms | 1400 KiB | 25 Q