3v4l.org

run code in 300+ PHP versions simultaneously
<?php function xor_encrypt($in) { $key = '<censored>'; $text = $in; $outText = ''; // Iterate through each character for($i=0;$i<strlen($text);$i++) { $outText .= $text[$i] ^ $key[$i % strlen($key)]; } return $outText; } // CALLED FIRST function loadData($def) { global $_COOKIE; $mydata = $def; // If data is in the cookie if(array_key_exists("data", $_COOKIE)) { // Get the data in rawform. base64 -> XORED -> json $tempdata = json_decode(xor_encrypt(base64_decode($_COOKIE["data"])), true); // outputs an assoc array with a key "showpassword" and "bgcolor" if(is_array($tempdata) && array_key_exists("showpassword", $tempdata) && array_key_exists("bgcolor", $tempdata)) { // If bg color looks like # + 6 of a-f then copy it over to mydata if (preg_match('/^#(?:[a-fd]{6})$/i', $tempdata['bgcolor'])) { $mydata['showpassword'] = $tempdata['showpassword']; $mydata['bgcolor'] = $tempdata['bgcolor']; } } } return $mydata; } // CALLED NEXT // go the other way function saveData($d) { setcookie("data", base64_encode(xor_encrypt(json_encode($d)))); } function decryptcookie($data){ $base64_decoded = base64_decode($data); $xored = xor_encrypt(base64_decode($data)); $json = json_decode(xor_encrypt(base64_decode($data)), true); $out = json_decode(xor_encrypt(base64_decode($data)), true); //////////////////////////////////////////////////////////////// echo "This is it:\n"; echo "HEXX: ". bin2hex($data)."\n"; echo "orig: ". $data."\n"; echo "base64 decoded: ".$base64_decoded."\n"; echo "xor: ".$xored."\n"; echo "json_decode: ".$json."\n"; echo "out: ". $out."\n\n"; //////////////////////////////////////////////////////////////// print_r($out); print_r(array_values($out)); echo "Type of based64:". gettype($base64_decoded)."\n"; echo "Type of xored:". gettype($xored)."\n"; echo "Type of json:". gettype($json)."\n"; echo "Type of out:". gettype($out); echo "\n****\n"; } ///////////////////////////////////////////// $defaultdata = array( "showpassword"=>"no", "bgcolor"=>"#ffffff"); // put the cookie data in the new data $data = loadData($defaultdata); // if the color is a valid hexcode then add it to the cookie if(array_key_exists("bgcolor",$_REQUEST)) { if (preg_match('/^#(?:[a-fd]{6})$/i', $_REQUEST['bgcolor'])) { $data['bgcolor'] = $_REQUEST['bgcolor']; } } saveData($data); $cook = "ClVLIh4ASCsCBE8lAxMacFMZV2hdVVotEhhUJQNVAmhSEV4sFxFeaAw="; $cook_alt = "ClVLIh4ASCsCBE8lAxMacFMZV2hdVVotEhhUJQNVAmhSEV4sFxFeaAw"; decryptcookie($cook); echo 'Hello World!';
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 19
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
Branch analysis from position: 19
filename:       /in/2v7fm
function name:  (null)
number of ops:  29
compiled vars:  !0 = $defaultdata, !1 = $data, !2 = $cook, !3 = $cook_alt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   77     0  E >   ASSIGN                                                   !0, <array>
   80     1        INIT_FCALL                                               'loaddata'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $5      
          4        ASSIGN                                                   !1, $5
   83     5        FETCH_R                      global              ~7      '_REQUEST'
          6        ARRAY_KEY_EXISTS                                         'bgcolor', ~7
          7      > JMPZ                                                     ~8, ->19
   84     8    >   INIT_FCALL                                               'preg_match'
          9        SEND_VAL                                                 '%2F%5E%23%28%3F%3A%5Ba-fd%5D%7B6%7D%29%24%2Fi'
         10        FETCH_R                      global              ~9      '_REQUEST'
         11        FETCH_DIM_R                                      ~10     ~9, 'bgcolor'
         12        SEND_VAL                                                 ~10
         13        DO_ICALL                                         $11     
         14      > JMPZ                                                     $11, ->19
   85    15    >   FETCH_R                      global              ~13     '_REQUEST'
         16        FETCH_DIM_R                                      ~14     ~13, 'bgcolor'
         17        ASSIGN_DIM                                               !1, 'bgcolor'
         18        OP_DATA                                                  ~14
   89    19    >   INIT_FCALL                                               'savedata'
         20        SEND_VAR                                                 !1
         21        DO_FCALL                                      0          
   91    22        ASSIGN                                                   !2, 'ClVLIh4ASCsCBE8lAxMacFMZV2hdVVotEhhUJQNVAmhSEV4sFxFeaAw%3D'
   92    23        ASSIGN                                                   !3, 'ClVLIh4ASCsCBE8lAxMacFMZV2hdVVotEhhUJQNVAmhSEV4sFxFeaAw'
   93    24        INIT_FCALL                                               'decryptcookie'
         25        SEND_VAR                                                 !2
         26        DO_FCALL                                      0          
   97    27        ECHO                                                     'Hello+World%21'
         28      > RETURN                                                   1

Function xor_encrypt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 6
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 6
Branch analysis from position: 16
Branch analysis from position: 6
filename:       /in/2v7fm
function name:  xor_encrypt
number of ops:  18
compiled vars:  !0 = $in, !1 = $key, !2 = $text, !3 = $outText, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, '%3Ccensored%3E'
    5     2        ASSIGN                                                   !2, !0
    6     3        ASSIGN                                                   !3, ''
    9     4        ASSIGN                                                   !4, 0
          5      > JMP                                                      ->13
   10     6    >   FETCH_DIM_R                                      ~9      !2, !4
          7        STRLEN                                           ~10     !1
          8        MOD                                              ~11     !4, ~10
          9        FETCH_DIM_R                                      ~12     !1, ~11
         10        BW_XOR                                           ~13     ~9, ~12
         11        ASSIGN_OP                                     8          !3, ~13
    9    12        PRE_INC                                                  !4
         13    >   STRLEN                                           ~16     !2
         14        IS_SMALLER                                               !4, ~16
         15      > JMPNZ                                                    ~17, ->6
   13    16    > > RETURN                                                   !3
   14    17*     > RETURN                                                   null

End of function xor_encrypt

Function loaddata:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 41
Branch analysis from position: 8
2 jumps found. (Code = 46) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
2 jumps found. (Code = 46) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 41
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 41
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
Branch analysis from position: 41
Branch analysis from position: 28
Branch analysis from position: 25
Branch analysis from position: 41
filename:       /in/2v7fm
function name:  loadData
number of ops:  43
compiled vars:  !0 = $def, !1 = $mydata, !2 = $tempdata
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        FETCH_W                      global lock         $3      '_COOKIE'
          2        FETCH_W                      global              $4      '_COOKIE'
          3        ASSIGN_REF                                               $4, $3
   19     4        ASSIGN                                                   !1, !0
   22     5        FETCH_R                      global              ~6      '_COOKIE'
          6        ARRAY_KEY_EXISTS                                         'data', ~6
          7      > JMPZ                                                     ~7, ->41
   25     8    >   INIT_FCALL                                               'json_decode'
          9        INIT_FCALL                                               'xor_encrypt'
         10        INIT_FCALL                                               'base64_decode'
         11        FETCH_R                      global              ~8      '_COOKIE'
         12        FETCH_DIM_R                                      ~9      ~8, 'data'
         13        SEND_VAL                                                 ~9
         14        DO_ICALL                                         $10     
         15        SEND_VAR                                                 $10
         16        DO_FCALL                                      0  $11     
         17        SEND_VAR                                                 $11
         18        SEND_VAL                                                 <true>
         19        DO_ICALL                                         $12     
         20        ASSIGN                                                   !2, $12
   28    21        TYPE_CHECK                                  128  ~14     !2
         22      > JMPZ_EX                                          ~14     ~14, ->25
         23    >   ARRAY_KEY_EXISTS                                 ~15     'showpassword', !2
         24        BOOL                                             ~14     ~15
         25    > > JMPZ_EX                                          ~14     ~14, ->28
         26    >   ARRAY_KEY_EXISTS                                 ~16     'bgcolor', !2
         27        BOOL                                             ~14     ~16
         28    > > JMPZ                                                     ~14, ->41
   31    29    >   INIT_FCALL                                               'preg_match'
         30        SEND_VAL                                                 '%2F%5E%23%28%3F%3A%5Ba-fd%5D%7B6%7D%29%24%2Fi'
         31        FETCH_DIM_R                                      ~17     !2, 'bgcolor'
         32        SEND_VAL                                                 ~17
         33        DO_ICALL                                         $18     
         34      > JMPZ                                                     $18, ->41
   32    35    >   FETCH_DIM_R                                      ~20     !2, 'showpassword'
         36        ASSIGN_DIM                                               !1, 'showpassword'
         37        OP_DATA                                                  ~20
   33    38        FETCH_DIM_R                                      ~22     !2, 'bgcolor'
         39        ASSIGN_DIM                                               !1, 'bgcolor'
         40        OP_DATA                                                  ~22
   37    41    > > RETURN                                                   !1
   38    42*     > RETURN                                                   null

End of function loaddata

Function savedata:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2v7fm
function name:  saveData
number of ops:  15
compiled vars:  !0 = $d
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   43     1        INIT_FCALL                                               'setcookie'
          2        SEND_VAL                                                 'data'
          3        INIT_FCALL                                               'base64_encode'
          4        INIT_FCALL                                               'xor_encrypt'
          5        INIT_FCALL                                               'json_encode'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $1      
          8        SEND_VAR                                                 $1
          9        DO_FCALL                                      0  $2      
         10        SEND_VAR                                                 $2
         11        DO_ICALL                                         $3      
         12        SEND_VAR                                                 $3
         13        DO_ICALL                                                 
   44    14      > RETURN                                                   null

End of function savedata

Function decryptcookie:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2v7fm
function name:  decryptcookie
number of ops:  82
compiled vars:  !0 = $data, !1 = $base64_decoded, !2 = $xored, !3 = $json, !4 = $out
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   48     1        INIT_FCALL                                               'base64_decode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $5      
          4        ASSIGN                                                   !1, $5
   49     5        INIT_FCALL                                               'xor_encrypt'
          6        INIT_FCALL                                               'base64_decode'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $7      
          9        SEND_VAR                                                 $7
         10        DO_FCALL                                      0  $8      
         11        ASSIGN                                                   !2, $8
   50    12        INIT_FCALL                                               'json_decode'
         13        INIT_FCALL                                               'xor_encrypt'
         14        INIT_FCALL                                               'base64_decode'
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                         $10     
         17        SEND_VAR                                                 $10
         18        DO_FCALL                                      0  $11     
         19        SEND_VAR                                                 $11
         20        SEND_VAL                                                 <true>
         21        DO_ICALL                                         $12     
         22        ASSIGN                                                   !3, $12
   51    23        INIT_FCALL                                               'json_decode'
         24        INIT_FCALL                                               'xor_encrypt'
         25        INIT_FCALL                                               'base64_decode'
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                         $14     
         28        SEND_VAR                                                 $14
         29        DO_FCALL                                      0  $15     
         30        SEND_VAR                                                 $15
         31        SEND_VAL                                                 <true>
         32        DO_ICALL                                         $16     
         33        ASSIGN                                                   !4, $16
   54    34        ECHO                                                     'This+is+it%3A%0A'
   55    35        INIT_FCALL                                               'bin2hex'
         36        SEND_VAR                                                 !0
         37        DO_ICALL                                         $18     
         38        CONCAT                                           ~19     'HEXX%3A+', $18
         39        CONCAT                                           ~20     ~19, '%0A'
         40        ECHO                                                     ~20
   56    41        CONCAT                                           ~21     'orig%3A+', !0
         42        CONCAT                                           ~22     ~21, '%0A'
         43        ECHO                                                     ~22
   57    44        CONCAT                                           ~23     'base64+decoded%3A+', !1
         45        CONCAT                                           ~24     ~23, '%0A'
         46        ECHO                                                     ~24
   58    47        CONCAT                                           ~25     'xor%3A+', !2
         48        CONCAT                                           ~26     ~25, '%0A'
         49        ECHO                                                     ~26
   59    50        CONCAT                                           ~27     'json_decode%3A+', !3
         51        CONCAT                                           ~28     ~27, '%0A'
         52        ECHO                                                     ~28
   60    53        CONCAT                                           ~29     'out%3A+', !4
         54        CONCAT                                           ~30     ~29, '%0A%0A'
         55        ECHO                                                     ~30
   64    56        INIT_FCALL                                               'print_r'
         57        SEND_VAR                                                 !4
         58        DO_ICALL                                                 
   66    59        INIT_FCALL                                               'print_r'
         60        INIT_FCALL                                               'array_values'
         61        SEND_VAR                                                 !4
         62        DO_ICALL                                         $32     
         63        SEND_VAR                                                 $32
         64        DO_ICALL                                                 
   68    65        GET_TYPE                                         ~34     !1
         66        CONCAT                                           ~35     'Type+of+based64%3A', ~34
         67        CONCAT                                           ~36     ~35, '%0A'
         68        ECHO                                                     ~36
   69    69        GET_TYPE                                         ~37     !2
         70        CONCAT                                           ~38     'Type+of+xored%3A', ~37
         71        CONCAT                                           ~39     ~38, '%0A'
         72        ECHO                                                     ~39
   70    73        GET_TYPE                                         ~40     !3
         74        CONCAT                                           ~41     'Type+of+json%3A', ~40
         75        CONCAT                                           ~42     ~41, '%0A'
         76        ECHO                                                     ~42
   71    77        GET_TYPE                                         ~43     !4
         78        CONCAT                                           ~44     'Type+of+out%3A', ~43
         79        ECHO                                                     ~44
   73    80        ECHO                                                     '%0A%2A%2A%2A%2A%0A'
   74    81      > RETURN                                                   null

End of function decryptcookie

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.34 ms | 1419 KiB | 39 Q