3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $data = "wpdPVWejqNRYqDTeUJ2Iw06/rnfHAoy5jtgTojiilD0="; $pwd = "ICS2015"; $salt = "7"; $enc = Encrypt("boy10@naver.com", $pwd, $salt); echo "Enc: " . $enc . "\r\n"; $dec = Decrypt($data, $pwd, $salt); echo "Dec: " . $dec . "\r\n"; function Decrypt($ciphertext, $password, $salt) { $ciphertext = base64_decode($ciphertext); $key = PBKDF1($password, $salt, 100, 32); $iv = PBKDF1($password, $salt, 100, 16); echo "bb" . base64_encode($iv); // NB: Need 128 not 256 and CBC mode to be compatible $decpad = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $ciphertext, MCRYPT_MODE_CBC, $iv); $pad = ord($decpad[($len = strlen($decpad)) - 1]); $dec = substr($decpad, 0, strlen($decpad) - $pad); return $dec; } function Encrypt($ciphertext, $password, $salt) { $key = PBKDF1($password, $salt, 100, 32); $iv = PBKDF1($password, $salt, 100, 16); echo "aa" . base64_encode($iv); return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $ciphertext, MCRYPT_MODE_CBC, $iv)); } function PBKDF1($pass, $salt, $count, $cb) { 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 = ""; 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; } ?>
based on 88DA5
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/201SW
function name:  (null)
number of ops:  25
compiled vars:  !0 = $data, !1 = $pwd, !2 = $salt, !3 = $enc, !4 = $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'
   8     3        INIT_FCALL_BY_NAME                                       'Encrypt'
         4        SEND_VAL_EX                                              'boy10%40naver.com'
         5        SEND_VAR_EX                                              !1
         6        SEND_VAR_EX                                              !2
         7        DO_FCALL                                      0  $8      
         8        ASSIGN                                                   !3, $8
   9     9        CONCAT                                           ~10     'Enc%3A+', !3
        10        CONCAT                                           ~11     ~10, '%0D%0A'
        11        ECHO                                                     ~11
  11    12        INIT_FCALL_BY_NAME                                       'Decrypt'
        13        SEND_VAR_EX                                              !0
        14        SEND_VAR_EX                                              !1
        15        SEND_VAR_EX                                              !2
        16        DO_FCALL                                      0  $12     
        17        ASSIGN                                                   !4, $12
  12    18        CONCAT                                           ~14     'Dec%3A+', !4
        19        CONCAT                                           ~15     ~14, '%0D%0A'
        20        ECHO                                                     ~15
  17    21        NOP                                                      
  35    22        NOP                                                      
  48    23        NOP                                                      
 121    24      > RETURN                                                   1

Function decrypt:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/201SW
function name:  Decrypt
number of ops:  54
compiled vars:  !0 = $ciphertext, !1 = $password, !2 = $salt, !3 = $key, !4 = $iv, !5 = $decpad, !6 = $pad, !7 = $len, !8 = $dec
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  17     0  E >   RECV                                             !0      
         1        RECV                                             !1      
         2        RECV                                             !2      
  19     3        INIT_FCALL                                               'base64_decode'
         4        SEND_VAR                                                 !0
         5        DO_ICALL                                         $9      
         6        ASSIGN                                                   !0, $9
  20     7        INIT_FCALL_BY_NAME                                       'PBKDF1'
         8        SEND_VAR_EX                                              !1
         9        SEND_VAR_EX                                              !2
        10        SEND_VAL_EX                                              100
        11        SEND_VAL_EX                                              32
        12        DO_FCALL                                      0  $11     
        13        ASSIGN                                                   !3, $11
  21    14        INIT_FCALL_BY_NAME                                       'PBKDF1'
        15        SEND_VAR_EX                                              !1
        16        SEND_VAR_EX                                              !2
        17        SEND_VAL_EX                                              100
        18        SEND_VAL_EX                                              16
        19        DO_FCALL                                      0  $13     
        20        ASSIGN                                                   !4, $13
  23    21        INIT_FCALL                                               'base64_encode'
        22        SEND_VAR                                                 !4
        23        DO_ICALL                                         $15     
        24        CONCAT                                           ~16     'bb', $15
        25        ECHO                                                     ~16
  26    26        INIT_FCALL                                               'mcrypt_decrypt'
        27        FETCH_CONSTANT                                   ~17     'MCRYPT_RIJNDAEL_128'
        28        SEND_VAL                                                 ~17
        29        SEND_VAR                                                 !3
        30        SEND_VAR                                                 !0
        31        FETCH_CONSTANT                                   ~18     'MCRYPT_MODE_CBC'
        32        SEND_VAL                                                 ~18
        33        SEND_VAR                                                 !4
        34        DO_ICALL                                         $19     
        35        ASSIGN                                                   !5, $19
  28    36        INIT_FCALL                                               'ord'
        37        STRLEN                                           ~21     !5
        38        ASSIGN                                           $22     !7, ~21
        39        SUB                                              ~23     $22, 1
        40        FETCH_DIM_R                                      $24     !5, ~23
        41        SEND_VAR                                                 $24
        42        DO_ICALL                                         $25     
        43        ASSIGN                                                   !6, $25
  29    44        INIT_FCALL                                               'substr'
        45        SEND_VAR                                                 !5
        46        SEND_VAL                                                 0
        47        STRLEN                                           ~27     !5
        48        SUB                                              ~28     ~27, !6
        49        SEND_VAL                                                 ~28
        50        DO_ICALL                                         $29     
        51        ASSIGN                                                   !8, $29
  31    52      > RETURN                                                   !8
  32    53*     > RETURN                                                   null

End of function decrypt

Function encrypt:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/201SW
function name:  Encrypt
number of ops:  36
compiled vars:  !0 = $ciphertext, !1 = $password, !2 = $salt, !3 = $key, !4 = $iv
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  35     0  E >   RECV                                             !0      
         1        RECV                                             !1      
         2        RECV                                             !2      
  39     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
  40    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
  42    17        INIT_FCALL                                               'base64_encode'
        18        SEND_VAR                                                 !4
        19        DO_ICALL                                         $9      
        20        CONCAT                                           ~10     'aa', $9
        21        ECHO                                                     ~10
  44    22        INIT_FCALL                                               'base64_encode'
        23        INIT_FCALL                                               'mcrypt_encrypt'
        24        FETCH_CONSTANT                                   ~11     'MCRYPT_RIJNDAEL_128'
        25        SEND_VAL                                                 ~11
        26        SEND_VAR                                                 !3
        27        SEND_VAR                                                 !0
        28        FETCH_CONSTANT                                   ~12     'MCRYPT_MODE_CBC'
        29        SEND_VAL                                                 ~12
        30        SEND_VAR                                                 !4
        31        DO_ICALL                                         $13     
        32        SEND_VAR                                                 $13
        33        DO_ICALL                                         $14     
        34      > RETURN                                                   $14
  46    35*     > RETURN                                                   null

End of function encrypt

Function pbkdf1:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 16, Position 2 = 36
Branch analysis from position: 16
Jump found. Position 1 = 34
Branch analysis from position: 34
Jump found. Position 1 = 36, Position 2 = 27
Branch analysis from position: 36
Jump found. Position 1 = 39, Position 2 = 63
Branch analysis from position: 39
Jump found. Position 1 = 44, Position 2 = 57
Branch analysis from position: 44
Jump found. Position 1 = 52, Position 2 = 54
Branch analysis from position: 52
Jump found. Position 1 = 56
Branch analysis from position: 56
Jump found. Position 1 = -2
Branch analysis from position: 54
Jump found. Position 1 = -2
Branch analysis from position: 57
Jump found. Position 1 = 95
Branch analysis from position: 95
Jump found. Position 1 = 97, Position 2 = 69
Branch analysis from position: 97
Jump found. Position 1 = 105, Position 2 = 107
Branch analysis from position: 105
Jump found. Position 1 = -2
Branch analysis from position: 107
Branch analysis from position: 69
Jump found. Position 1 = 71, Position 2 = 77
Branch analysis from position: 71
Jump found. Position 1 = 91
Branch analysis from position: 91
Jump found. Position 1 = 97, Position 2 = 69
Branch analysis from position: 97
Branch analysis from position: 69
Branch analysis from position: 77
Jump found. Position 1 = 79, Position 2 = 91
Branch analysis from position: 79
Jump found. Position 1 = 97, Position 2 = 69
Branch analysis from position: 97
Branch analysis from position: 69
Branch analysis from position: 91
Branch analysis from position: 63
Branch analysis from position: 27
Jump found. Position 1 = 36, Position 2 = 27
Branch analysis from position: 36
Branch analysis from position: 27
Branch analysis from position: 36
filename:       /in/201SW
function name:  PBKDF1
number of ops:  109
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
-------------------------------------------------------------------------------------
  48     0  E >   RECV                                             !0      
         1        RECV                                             !1      
         2        RECV                                             !2      
         3        RECV                                             !3      
  50     4        FETCH_W                      static              $18     'base'
         5        ASSIGN_REF                                               !4, $18
  51     6        FETCH_W                      static              $19     'extra'
         7        ASSIGN_REF                                               !5, $19
  52     8        FETCH_W                      static              $20     'extracount'
         9        ASSIGN_REF                                               !6, $20
  53    10        FETCH_W                      static              $21     'hashno'
        11        ASSIGN_REF                                               !7, $21
  54    12        FETCH_W                      static              $22     'state'
        13        ASSIGN_REF                                               !8, $22
  56    14        IS_EQUAL                                         ~23     !8, 0
        15      > JMPZ                                                     ~23, ->36
  58    16    >   ASSIGN                                                   !7, 0
  59    17        ASSIGN                                                   !8, 1
  61    18        CONCAT                                           ~26     !0, !1
        19        ASSIGN                                                   !9, ~26
  62    20        INIT_FCALL                                               'sha1'
        21        SEND_VAR                                                 !9
        22        SEND_VAL                                                 <true>
        23        DO_ICALL                                         $28     
        24        ASSIGN                                                   !4, $28
  63    25        ASSIGN                                                   !10, 2
        26      > JMP                                                      ->34
  65    27    >   INIT_FCALL                                               'sha1'
        28        SEND_VAR                                                 !4
        29        SEND_VAL                                                 <true>
        30        DO_ICALL                                         $31     
        31        ASSIGN                                                   !4, $31
  63    32        POST_INC                                         ~33     !10
        33        FREE                                                     ~33
        34    >   IS_SMALLER                                       ~34     !10, !2
        35      > JMPNZ                                                    ~34, ->27
  69    36    >   ASSIGN                                                   !11, ''
  71    37        IS_SMALLER                                       ~36     0, !6
        38      > JMPZ                                                     ~36, ->63
  73    39    >   STRLEN                                           ~37     !5
        40        SUB                                              ~38     ~37, !6
        41        ASSIGN                                                   !12, ~38
  74    42        IS_SMALLER_OR_EQUAL                              ~40     !3, !12
        43      > JMPZ                                                     ~40, ->57
  76    44    >   INIT_FCALL                                               'substr'
        45        SEND_VAR                                                 !5
        46        SEND_VAR                                                 !6
        47        SEND_VAR                                                 !3
        48        DO_ICALL                                         $41     
        49        ASSIGN                                                   !11, $41
  77    50        IS_SMALLER                                       ~43     !3, !12
        51      > JMPZ                                                     ~43, ->54
  79    52    >   ASSIGN_ADD                                    0          !6, !3
        53      > JMP                                                      ->56
  83    54    >   ASSIGN                                                   !5, null
  84    55        ASSIGN                                                   !6, 0
  86    56    > > RETURN                                                   !11
  88    57    >   INIT_FCALL                                               'substr'
        58        SEND_VAR                                                 !5
        59        SEND_VAR                                                 !12
        60        SEND_VAR                                                 !12
        61        DO_ICALL                                         $47     
        62        ASSIGN                                                   !11, $47
  91    63    >   ASSIGN                                                   !13, ''
  92    64        ASSIGN                                                   !14, 0
  93    65        STRLEN                                           ~51     !11
        66        SUB                                              ~52     !3, ~51
        67        ASSIGN                                                   !15, ~52
  94    68      > JMP                                                      ->95
  96    69    >   IS_EQUAL                                         ~54     !7, 0
        70      > JMPZ                                                     ~54, ->77
  98    71    >   INIT_FCALL                                               'sha1'
        72        SEND_VAR                                                 !4
        73        SEND_VAL                                                 <true>
        74        DO_ICALL                                         $55     
        75        ASSIGN                                                   !13, $55
        76      > JMP                                                      ->91
 100    77    >   IS_SMALLER                                       ~57     !7, 1000
        78      > JMPZ                                                     ~57, ->91
 102    79    >   INIT_FCALL                                               'sprintf'
        80        SEND_VAL                                                 '%25d'
        81        SEND_VAR                                                 !7
        82        DO_ICALL                                         $58     
        83        ASSIGN                                                   !16, $58
 103    84        CONCAT                                           ~60     !16, !4
        85        ASSIGN                                                   !17, ~60
 104    86        INIT_FCALL                                               'sha1'
        87        SEND_VAR                                                 !17
        88        SEND_VAL                                                 <true>
        89        DO_ICALL                                         $62     
        90        ASSIGN_CONCAT                                 0          !13, $62
 106    91    >   POST_INC                                         ~64     !7
        92        FREE                                                     ~64
 107    93        STRLEN                                           ~65     !13
        94        ASSIGN                                                   !14, ~65
  94    95    >   IS_SMALLER                                       ~67     !14, !15
        96      > JMPNZ                                                    ~67, ->69
 111    97    >   INIT_FCALL                                               'substr'
        98        SEND_VAR                                                 !13
        99        SEND_VAL                                                 0
       100        SEND_VAR                                                 !15
       101        DO_ICALL                                         $68     
       102        ASSIGN_CONCAT                                 0          !11, $68
 114   103        IS_SMALLER                                       ~70     !15, !14
       104      > JMPZ                                                     ~70, ->107
 116   105    >   ASSIGN                                                   !5, !13
 117   106        ASSIGN                                                   !6, !15
 120   107    > > RETURN                                                   !11
 121   108*     > RETURN                                                   null

End of function pbkdf1

Generated using Vulcan Logic Dumper, using php 7.3.0