View Single Post
Old 11.08.2007, 18:21   #21
Kenjiro
Архивный участник
 
Join Date: Apr 2006
Posts: 120
Default

Yes, you're right, all variables should be initialized before use, thus in my version is:
PHP Code:
$dst = $key = array ( 0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0 );

for ( 
$i = 0; $i < strlen ( $plain ); $i++ ) {
  
$dst [ $i ] = $key [ $i ] = ord ( substr ( $plain, $i, 1 ) );
} 
Btw, $dst and $key variables is integers, not characters, thus this should be (for sake of correctness):
PHP Code:
$key[$i] = $dst[$i] = 0; 
Of course it'll work with $dst[$i] = '' because of dynamic typing in PHP, but you should have in mind that future version could have some another type management (maybe explicit type conversions?).
Kenjiro is offline