3v4l.org

run code in 300+ PHP versions simultaneously
<?php $encb64 = "wpdPVWejqNRYqDTeUJ2Iw06/rnfHAoy5jtgTojiilD0="; $pwd = "ICS2015"; $salt = "7"; $enc = base64_decode($encb64); $decpad = Decrypt($enc, $pwd, $salt); // Remove the padding $pad = ord($decpad[($len = strlen($decpad)) - 1]); $dec = substr($decpad, 0, strlen($decpad) - $pad); echo "Enc: " . bin2hex($enc) . "\r\n"; echo "Dec: " . $dec . "\r\n"; function Decrypt($ciphertext, $password, $salt) { $key = PBKDF1($password, $salt, 100, 32); $iv = PBKDF1($password, $salt, 100, 16); // NB: Need 128 not 256 and CBC mode to be compatible return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $ciphertext, MCRYPT_MODE_CBC, $iv); } function PBKDF1($pass, $salt, $count, $cb) { // This is very approximately the way that the Microsoft version of // PasswordDeriveBytes works. /// /// !!!WARNING!!! /// // This is a BAD function! // Irrespective of the fact that the use of PBKDF1 is not recommended anyway. // // This really should be put into a class with a constructor taking the // $pass, $salt and $count. // Then there should be a Reset() method to start from scratch each time a new pwd/salt is used. // And there should be a GetBytes(int) method to get the required info. // But for the sake of simplicity we are assuming the same pwd and salt for each call to // this function. This will not stand up to any scrutiny! static $base; static $extra; static $extracount= 0; static $hashno; static $state = 0; if ($state == 0) { $hashno = 0; $state = 1; $key = $pass . $salt; $base = sha1($key, true); for($i = 2; $i < $count; $i++) { $base = sha1($base, true); } } $result = ""; // Check if we have any bytes left over from a previous iteration. // This is the way MS appears to do it. To me it looks very badly wrong // in the line: "$result = substr($extra, $rlen, $rlen);" // I'm sure it should be more like "$result = substr($extra, $extracount, $rlen);" // Mono have provided what looks like a fixed version at // https://github.com/mono/mono/blob/master/mcs/class/corlib/System.Security.Cryptography/PasswordDeriveBytes.cs // But I'm no cryptographer so I might be wrong. // But this seems to work for low values of $hashno and seems to work // with C# implementations. if ($extracount > 0) { $rlen = strlen($extra) - $extracount; if ($rlen >= $cb) { $result = substr($extra, $extracount, $cb); if ($rlen > $cb) { $extracount += $cb; } else { $extra = null; $extracount = 0; } return $result; } $result = substr($extra, $rlen, $rlen); } $current = ""; $clen = 0; $remain = $cb - strlen($result); while ($remain > $clen) { if ($hashno == 0) { $current = sha1($base, true); } else if ($hashno < 1000) { $n = sprintf("%d", $hashno); $tmp = $n . $base; $current .= sha1($tmp, true); } $hashno++; $clen = strlen($current); } // $current now holds at least as many bytes as we need $result .= substr($current, 0, $remain); // Save any left over bytes for any future requests if ($clen > $remain) { $extra = $current; $extracount = $remain; } return $result; } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GqMH3
function name:  (null)
number of ops:  39
compiled vars:  !0 = $encb64, !1 = $pwd, !2 = $salt, !3 = $enc, !4 = $decpad, !5 = $pad, !6 = $len, !7 = $dec
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'wpdPVWejqNRYqDTeUJ2Iw06%2FrnfHAoy5jtgTojiilD0%3D'
    3     1        ASSIGN                                                   !1, 'ICS2015'
    4     2        ASSIGN                                                   !2, '7'
    6     3        INIT_FCALL                                               'base64_decode'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $11     
          6        ASSIGN                                                   !3, $11
    7     7        INIT_FCALL_BY_NAME                                       'Decrypt'
          8        SEND_VAR_EX                                              !3
          9        SEND_VAR_EX                                              !1
         10        SEND_VAR_EX                                              !2
         11        DO_FCALL                                      0  $13     
         12        ASSIGN                                                   !4, $13
    9    13        INIT_FCALL                                               'ord'
         14        STRLEN                                           ~15     !4
         15        ASSIGN                                           ~16     !6, ~15
         16        SUB                                              ~17     ~16, 1
         17        FETCH_DIM_R                                      ~18     !4, ~17
         18        SEND_VAL                                                 ~18
         19        DO_ICALL                                         $19     
         20        ASSIGN                                                   !5, $19
   10    21        INIT_FCALL                                               'substr'
         22        SEND_VAR                                                 !4
         23        SEND_VAL                                                 0
         24        STRLEN                                           ~21     !4
         25        SUB                                              ~22     ~21, !5
         26        SEND_VAL                                                 ~22
         27        DO_ICALL                                         $23     
         28        ASSIGN                                                   !7, $23
   12    29        INIT_FCALL                                               'bin2hex'
         30        SEND_VAR                                                 !3
         31        DO_ICALL                                         $25     
         32        CONCAT                                           ~26     'Enc%3A+', $25
         33        CONCAT                                           ~27     ~26, '%0D%0A'
         34        ECHO                                                     ~27
   13    35        CONCAT                                           ~28     'Dec%3A+', !7
         36        CONCAT                                           ~29     ~28, '%0D%0A'
         37        ECHO                                                     ~29
  125    38      > RETURN                                                   1

Function decrypt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GqMH3
function name:  Decrypt
number of ops:  28
compiled vars:  !0 = $ciphertext, !1 = $password, !2 = $salt, !3 = $key, !4 = $iv
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   17     3        INIT_FCALL_BY_NAME                                       'PBKDF1'
          4        SEND_VAR_EX                                              !1
          5        SEND_VAR_EX                                              !2
          6        SEND_VAL_EX                                              100
          7        SEND_VAL_EX                                              32
          8        DO_FCALL                                      0  $5      
          9        ASSIGN                                                   !3, $5
   18    10        INIT_FCALL_BY_NAME                                       'PBKDF1'
         11        SEND_VAR_EX                                              !1
         12        SEND_VAR_EX                                              !2
         13        SEND_VAL_EX                                              100
         14        SEND_VAL_EX                                              16
         15        DO_FCALL                                      0  $7      
         16        ASSIGN                                                   !4, $7
   21    17        INIT_FCALL_BY_NAME                                       'mcrypt_decrypt'
         18        FETCH_CONSTANT                                   ~9      'MCRYPT_RIJNDAEL_128'
         19        SEND_VAL_EX                                              ~9
         20        SEND_VAR_EX                                              !3
         21        SEND_VAR_EX                                              !0
         22        FETCH_CONSTANT                                   ~10     'MCRYPT_MODE_CBC'
         23        SEND_VAL_EX                                              ~10
         24        SEND_VAR_EX                                              !4
         25        DO_FCALL                                      0  $11     
         26      > RETURN                                                   $11
   22    27*     > RETURN                                                   null

End of function decrypt

Function pbkdf1:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 30
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 22
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 57
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 51
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 48
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 88
Branch analysis from position: 88
2 jumps found. (Code = 44) Position 1 = 90, Position 2 = 63
Branch analysis from position: 90
2 jumps found. (Code = 43) Position 1 = 98, Position 2 = 100
Branch analysis from position: 98
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 100
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 71
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 85
Branch analysis from position: 85
2 jumps found. (Code = 44) Position 1 = 90, Position 2 = 63
Branch analysis from position: 90
Branch analysis from position: 63
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 85
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 90, Position 2 = 63
Branch analysis from position: 90
Branch analysis from position: 63
Branch analysis from position: 85
Branch analysis from position: 57
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 22
Branch analysis from position: 30
Branch analysis from position: 22
Branch analysis from position: 30
filename:       /in/GqMH3
function name:  PBKDF1
number of ops:  102
compiled vars:  !0 = $pass, !1 = $salt, !2 = $count, !3 = $cb, !4 = $base, !5 = $extra, !6 = $extracount, !7 = $hashno, !8 = $state, !9 = $key, !10 = $i, !11 = $result, !12 = $rlen, !13 = $current, !14 = $clen, !15 = $remain, !16 = $n, !17 = $tmp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   43     4        BIND_STATIC                                              !4
   44     5        BIND_STATIC                                              !5
   45     6        BIND_STATIC                                              !6
   46     7        BIND_STATIC                                              !7
   47     8        BIND_STATIC                                              !8
   49     9        IS_EQUAL                                                 !8, 0
         10      > JMPZ                                                     ~18, ->30
   51    11    >   ASSIGN                                                   !7, 0
   52    12        ASSIGN                                                   !8, 1
   54    13        CONCAT                                           ~21     !0, !1
         14        ASSIGN                                                   !9, ~21
   55    15        INIT_FCALL                                               'sha1'
         16        SEND_VAR                                                 !9
         17        SEND_VAL                                                 <true>
         18        DO_ICALL                                         $23     
         19        ASSIGN                                                   !4, $23
   56    20        ASSIGN                                                   !10, 2
         21      > JMP                                                      ->28
   58    22    >   INIT_FCALL                                               'sha1'
         23        SEND_VAR                                                 !4
         24        SEND_VAL                                                 <true>
         25        DO_ICALL                                         $26     
         26        ASSIGN                                                   !4, $26
   56    27        PRE_INC                                                  !10
         28    >   IS_SMALLER                                               !10, !2
         29      > JMPNZ                                                    ~29, ->22
   62    30    >   ASSIGN                                                   !11, ''
   74    31        IS_SMALLER                                               0, !6
         32      > JMPZ                                                     ~31, ->57
   76    33    >   STRLEN                                           ~32     !5
         34        SUB                                              ~33     ~32, !6
         35        ASSIGN                                                   !12, ~33
   77    36        IS_SMALLER_OR_EQUAL                                      !3, !12
         37      > JMPZ                                                     ~35, ->51
   79    38    >   INIT_FCALL                                               'substr'
         39        SEND_VAR                                                 !5
         40        SEND_VAR                                                 !6
         41        SEND_VAR                                                 !3
         42        DO_ICALL                                         $36     
         43        ASSIGN                                                   !11, $36
   80    44        IS_SMALLER                                               !3, !12
         45      > JMPZ                                                     ~38, ->48
   82    46    >   ASSIGN_OP                                     1          !6, !3
         47      > JMP                                                      ->50
   86    48    >   ASSIGN                                                   !5, null
   87    49        ASSIGN                                                   !6, 0
   89    50    > > RETURN                                                   !11
   91    51    >   INIT_FCALL                                               'substr'
         52        SEND_VAR                                                 !5
         53        SEND_VAR                                                 !12
         54        SEND_VAR                                                 !12
         55        DO_ICALL                                         $42     
         56        ASSIGN                                                   !11, $42
   94    57    >   ASSIGN                                                   !13, ''
   95    58        ASSIGN                                                   !14, 0
   96    59        STRLEN                                           ~46     !11
         60        SUB                                              ~47     !3, ~46
         61        ASSIGN                                                   !15, ~47
   97    62      > JMP                                                      ->88
   99    63    >   IS_EQUAL                                                 !7, 0
         64      > JMPZ                                                     ~49, ->71
  101    65    >   INIT_FCALL                                               'sha1'
         66        SEND_VAR                                                 !4
         67        SEND_VAL                                                 <true>
         68        DO_ICALL                                         $50     
         69        ASSIGN                                                   !13, $50
         70      > JMP                                                      ->85
  103    71    >   IS_SMALLER                                               !7, 1000
         72      > JMPZ                                                     ~52, ->85
  105    73    >   INIT_FCALL                                               'sprintf'
         74        SEND_VAL                                                 '%25d'
         75        SEND_VAR                                                 !7
         76        DO_ICALL                                         $53     
         77        ASSIGN                                                   !16, $53
  106    78        CONCAT                                           ~55     !16, !4
         79        ASSIGN                                                   !17, ~55
  107    80        INIT_FCALL                                               'sha1'
         81        SEND_VAR                                                 !17
         82        SEND_VAL                                                 <true>
         83        DO_ICALL                                         $57     
         84        ASSIGN_OP                                     8          !13, $57
  109    85    >   PRE_INC                                                  !7
  110    86        STRLEN                                           ~60     !13
         87        ASSIGN                                                   !14, ~60
   97    88    >   IS_SMALLER                                               !14, !15
         89      > JMPNZ                                                    ~62, ->63
  114    90    >   INIT_FCALL                                               'substr'
         91        SEND_VAR                                                 !13
         92        SEND_VAL                                                 0
         93        SEND_VAR                                                 !15
         94        DO_ICALL                                         $63     
         95        ASSIGN_OP                                     8          !11, $63
  117    96        IS_SMALLER                                               !15, !14
         97      > JMPZ                                                     ~65, ->100
  119    98    >   ASSIGN                                                   !5, !13
  120    99        ASSIGN                                                   !6, !15
  123   100    > > RETURN                                                   !11
  124   101*     > RETURN                                                   null

End of function pbkdf1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.32 ms | 1412 KiB | 25 Q