3v4l.org

run code in 300+ PHP versions simultaneously
<?php function csidAES($strMessage, $strKey, $strOperation = 'encrypt') { /** * csidAES * Provides encryption (default) and decryption suitable for use with the CSID SMS API. * @license CSID Partner Restricted * @param string $strMessage The message (cleartext or cyphertext) on which to operate. * @param string $strKey The agreed-upon encryption key. * @param string $strOperation OPTIONAL: One of 'encrypt' or 'decrypt' (default: * 'encrypt'). * @return string|bool Returns the resulting text, or FALSE on failure. */ echo $strMessage . ' is input to : ' . $strOperation . "<br/>"; switch ($strOperation){ case 'encrypt': echo "md5 of '".$strMessage . "' is : " . md5($strMessage) . "<br/>"; $AES_KEY = substr(md5($strKey), 0, 16); $iv = mcrypt_create_iv(16, MCRYPT_RAND); echo $iv . " - random generated IV<br/>"; //Perform encryption $ctext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $AES_KEY, $strMessage, MCRYPT_MODE_CBC, $iv); echo $ctext . " - encrypted<br/>"; $ctext = $iv.$ctext; echo $ctext . " - iv.ctext<br/>"; // Base64-encode, then urlencode the ciphertext $ctext = urlencode(base64_encode($ctext)); echo $ctext . " - url encoded ctext<br/>"; return $ctext; break; case 'decrypt': $key_size = mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); echo $key_size . " - key_size<br/>"; $AES_KEY = substr(md5($strKey), 0, 16); echo $AES_KEY . " - AES_KEY<br/>"; $iv = mcrypt_create_iv(16, MCRYPT_RAND); echo $iv . " - random generated IV<br/>"; //Perform a base64_decode. $ctext = base64_decode($strMessage); echo $ctext . " - decoded input<br/>"; $thIV = substr($ctext,0,16); echo "thIV : " . $thIV . "<br/>"; $thingForDecoding = substr($ctext,16); echo "thingForDecoding : " . $thingForDecoding . "<br/>"; //NOTE: No need to urldecode; the API server did it for us. //Perform decryption $ptext = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $AES_KEY, $ctext, MCRYPT_MODE_CBC, $iv); echo $ptext . " - decrypted<br/>"; $ptext = substr($ptext,16); echo $ptext . " - a substring of it"; $final = str_replace(chr(0),"",$ptext); echo $final . " - final"; return $final;//str_replace(chr(0),"",$ptext); break; default: return false; break; } } $csIDn = new ReflectionFunction('csidAES'); $originalText = 'Mirko Atanasov'; $encrypted = $csIDn->invoke($originalText , 'g3rWsiNm7Gwh9qMc','encrypt'); echo $encrypted; echo "<br/><br/> and now the decryption<br/><br/>"; $decrypted = $csIDn->invoke($encrypted, 'g3rWsiNm7Gwh9qMc','decrypt'); echo $decrypted; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0R63g
function name:  (null)
number of ops:  21
compiled vars:  !0 = $csIDn, !1 = $originalText, !2 = $encrypted, !3 = $decrypted
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   NEW                                              $4      'ReflectionFunction'
          1        SEND_VAL_EX                                              'csidAES'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $4
   67     4        ASSIGN                                                   !1, 'Mirko+Atanasov'
   68     5        INIT_METHOD_CALL                                         !0, 'invoke'
          6        SEND_VAR_EX                                              !1
          7        SEND_VAL_EX                                              'g3rWsiNm7Gwh9qMc'
          8        SEND_VAL_EX                                              'encrypt'
          9        DO_FCALL                                      0  $8      
         10        ASSIGN                                                   !2, $8
   69    11        ECHO                                                     !2
   70    12        ECHO                                                     '%3Cbr%2F%3E%3Cbr%2F%3E+and+now+the+decryption%3Cbr%2F%3E%3Cbr%2F%3E'
   71    13        INIT_METHOD_CALL                                         !0, 'invoke'
         14        SEND_VAR_EX                                              !2
         15        SEND_VAL_EX                                              'g3rWsiNm7Gwh9qMc'
         16        SEND_VAL_EX                                              'decrypt'
         17        DO_FCALL                                      0  $10     
         18        ASSIGN                                                   !3, $10
   72    19        ECHO                                                     !3
   73    20      > RETURN                                                   1

Function csidaes:
Finding entry points
Branch analysis from position: 0
4 jumps found. (Code = 188) Position 1 = 13, Position 2 = 65, Position 3 = 145, Position 4 = 8
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 145
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 65
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 145
Branch analysis from position: 145
Branch analysis from position: 65
Branch analysis from position: 13
filename:       /in/0R63g
function name:  csidAES
number of ops:  148
compiled vars:  !0 = $strMessage, !1 = $strKey, !2 = $strOperation, !3 = $AES_KEY, !4 = $iv, !5 = $ctext, !6 = $key_size, !7 = $thIV, !8 = $thingForDecoding, !9 = $ptext, !10 = $final
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      'encrypt'
   14     3        CONCAT                                           ~11     !0, '+is+input+to+%3A+'
          4        CONCAT                                           ~12     ~11, !2
          5        CONCAT                                           ~13     ~12, '%3Cbr%2F%3E'
          6        ECHO                                                     ~13
   15     7      > SWITCH_STRING                                            !2, [ 'encrypt':->13, 'decrypt':->65, ], ->145
   16     8    >   IS_EQUAL                                                 !2, 'encrypt'
          9      > JMPNZ                                                    ~14, ->13
   31    10    >   IS_EQUAL                                                 !2, 'decrypt'
         11      > JMPNZ                                                    ~14, ->65
         12    > > JMP                                                      ->145
   17    13    >   CONCAT                                           ~15     'md5+of+%27', !0
         14        CONCAT                                           ~16     ~15, '%27+is+%3A+'
         15        INIT_FCALL                                               'md5'
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                         $17     
         18        CONCAT                                           ~18     ~16, $17
         19        CONCAT                                           ~19     ~18, '%3Cbr%2F%3E'
         20        ECHO                                                     ~19
   18    21        INIT_FCALL                                               'substr'
         22        INIT_FCALL                                               'md5'
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                         $20     
         25        SEND_VAR                                                 $20
         26        SEND_VAL                                                 0
         27        SEND_VAL                                                 16
         28        DO_ICALL                                         $21     
         29        ASSIGN                                                   !3, $21
   19    30        INIT_FCALL_BY_NAME                                       'mcrypt_create_iv'
         31        SEND_VAL_EX                                              16
         32        FETCH_CONSTANT                                   ~23     'MCRYPT_RAND'
         33        SEND_VAL_EX                                              ~23
         34        DO_FCALL                                      0  $24     
         35        ASSIGN                                                   !4, $24
   20    36        CONCAT                                           ~26     !4, '+-+random+generated+IV%3Cbr%2F%3E'
         37        ECHO                                                     ~26
   22    38        INIT_FCALL_BY_NAME                                       'mcrypt_encrypt'
         39        FETCH_CONSTANT                                   ~27     'MCRYPT_RIJNDAEL_128'
         40        SEND_VAL_EX                                              ~27
         41        SEND_VAR_EX                                              !3
         42        SEND_VAR_EX                                              !0
         43        FETCH_CONSTANT                                   ~28     'MCRYPT_MODE_CBC'
         44        SEND_VAL_EX                                              ~28
         45        SEND_VAR_EX                                              !4
         46        DO_FCALL                                      0  $29     
         47        ASSIGN                                                   !5, $29
   23    48        CONCAT                                           ~31     !5, '+-+encrypted%3Cbr%2F%3E'
         49        ECHO                                                     ~31
   24    50        CONCAT                                           ~32     !4, !5
         51        ASSIGN                                                   !5, ~32
   25    52        CONCAT                                           ~34     !5, '+-+iv.ctext%3Cbr%2F%3E'
         53        ECHO                                                     ~34
   27    54        INIT_FCALL                                               'urlencode'
         55        INIT_FCALL                                               'base64_encode'
         56        SEND_VAR                                                 !5
         57        DO_ICALL                                         $35     
         58        SEND_VAR                                                 $35
         59        DO_ICALL                                         $36     
         60        ASSIGN                                                   !5, $36
   28    61        CONCAT                                           ~38     !5, '+-+url+encoded+ctext%3Cbr%2F%3E'
         62        ECHO                                                     ~38
   29    63      > RETURN                                                   !5
   30    64*       JMP                                                      ->147
   32    65    >   INIT_FCALL_BY_NAME                                       'mcrypt_get_key_size'
         66        FETCH_CONSTANT                                   ~39     'MCRYPT_RIJNDAEL_128'
         67        SEND_VAL_EX                                              ~39
         68        FETCH_CONSTANT                                   ~40     'MCRYPT_MODE_CBC'
         69        SEND_VAL_EX                                              ~40
         70        DO_FCALL                                      0  $41     
         71        ASSIGN                                                   !6, $41
   33    72        CONCAT                                           ~43     !6, '+-+key_size%3Cbr%2F%3E'
         73        ECHO                                                     ~43
   34    74        INIT_FCALL                                               'substr'
         75        INIT_FCALL                                               'md5'
         76        SEND_VAR                                                 !1
         77        DO_ICALL                                         $44     
         78        SEND_VAR                                                 $44
         79        SEND_VAL                                                 0
         80        SEND_VAL                                                 16
         81        DO_ICALL                                         $45     
         82        ASSIGN                                                   !3, $45
   35    83        CONCAT                                           ~47     !3, '+-+AES_KEY%3Cbr%2F%3E'
         84        ECHO                                                     ~47
   36    85        INIT_FCALL_BY_NAME                                       'mcrypt_create_iv'
         86        SEND_VAL_EX                                              16
         87        FETCH_CONSTANT                                   ~48     'MCRYPT_RAND'
         88        SEND_VAL_EX                                              ~48
         89        DO_FCALL                                      0  $49     
         90        ASSIGN                                                   !4, $49
   37    91        CONCAT                                           ~51     !4, '+-+random+generated+IV%3Cbr%2F%3E'
         92        ECHO                                                     ~51
   39    93        INIT_FCALL                                               'base64_decode'
         94        SEND_VAR                                                 !0
         95        DO_ICALL                                         $52     
         96        ASSIGN                                                   !5, $52
   40    97        CONCAT                                           ~54     !5, '+-+decoded+input%3Cbr%2F%3E'
         98        ECHO                                                     ~54
   44    99        INIT_FCALL                                               'substr'
        100        SEND_VAR                                                 !5
        101        SEND_VAL                                                 0
        102        SEND_VAL                                                 16
        103        DO_ICALL                                         $55     
        104        ASSIGN                                                   !7, $55
   45   105        CONCAT                                           ~57     'thIV+%3A+', !7
        106        CONCAT                                           ~58     ~57, '%3Cbr%2F%3E'
        107        ECHO                                                     ~58
   47   108        INIT_FCALL                                               'substr'
        109        SEND_VAR                                                 !5
        110        SEND_VAL                                                 16
        111        DO_ICALL                                         $59     
        112        ASSIGN                                                   !8, $59
   48   113        CONCAT                                           ~61     'thingForDecoding+%3A+', !8
        114        CONCAT                                           ~62     ~61, '%3Cbr%2F%3E'
        115        ECHO                                                     ~62
   52   116        INIT_FCALL_BY_NAME                                       'mcrypt_decrypt'
        117        FETCH_CONSTANT                                   ~63     'MCRYPT_RIJNDAEL_128'
        118        SEND_VAL_EX                                              ~63
        119        SEND_VAR_EX                                              !3
        120        SEND_VAR_EX                                              !5
   53   121        FETCH_CONSTANT                                   ~64     'MCRYPT_MODE_CBC'
        122        SEND_VAL_EX                                              ~64
   52   123        SEND_VAR_EX                                              !4
        124        DO_FCALL                                      0  $65     
        125        ASSIGN                                                   !9, $65
   54   126        CONCAT                                           ~67     !9, '+-+decrypted%3Cbr%2F%3E'
        127        ECHO                                                     ~67
   55   128        INIT_FCALL                                               'substr'
        129        SEND_VAR                                                 !9
        130        SEND_VAL                                                 16
        131        DO_ICALL                                         $68     
        132        ASSIGN                                                   !9, $68
   56   133        CONCAT                                           ~70     !9, '+-+a+substring+of+it'
        134        ECHO                                                     ~70
   57   135        INIT_FCALL                                               'str_replace'
        136        SEND_VAL                                                 '%00'
        137        SEND_VAL                                                 ''
        138        SEND_VAR                                                 !9
        139        DO_ICALL                                         $71     
        140        ASSIGN                                                   !10, $71
   58   141        CONCAT                                           ~73     !10, '+-+final'
        142        ECHO                                                     ~73
   59   143      > RETURN                                                   !10
   60   144*       JMP                                                      ->147
   62   145    > > RETURN                                                   <false>
   63   146*       JMP                                                      ->147
   65   147*     > RETURN                                                   null

End of function csidaes

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.76 ms | 1408 KiB | 25 Q