Hey Folks!
I've been writing some code for a small project and saw PHP crashing every
time.
The Code:
<?php
/*
* XOR buffer v1
/
class XoRb {
/ Set buffer ( -> write genPad to file ) in bit */
public $buffer = 4096;
public function encrypt($InputString, $KeyPhrase){
$KeyPhraseLength = strlen($KeyPhrase);
for ($i = 0, $strlen = strlen($InputString); $i <
$strlen; $i++)
$InputString[$i] = chr( (
ord($InputString[$i]) ^ ord( $KeyPhrase[ ( $i % $KeyPhraseLength ) ] ) ) );
return $InputString;
}
public function genPad ( $input ) {
for ( $i = 1, $o = null, $strlen = strlen($input);
$i <= $strlen; ++$i )
$o .= chr( mt_rand( 10, 300 ) );
return $o;
}
public function writePad ( $file, $byte, $buffer = false ) {
$fo = fopen( $file, "a+");
if ( !$buffer ) $buffer = $this -> buffer;
if ( $byte < $buffer ) $buffer = $byte;
for ( $i = 1, $o = null; $i <= $byte; ++$i ) {
$o .= chr( mt_rand( 10, 300 ) );
if ( strlen( $o ) <= $buffer + 20 )
print "Writing buffer " . chr ( $i %
$buffer ) . "\n" and fwrite( $fo, $o ) and $o = null;
}
}
}
$xor = new XoRb;
$xor -> buffer = 1024;
$xor -> writePad ( 'int.dat', 8192 * 1000 );
/* //Interface
while ( true ) {
print "Input: ";
$input = trim(fgets(fopen("php://stdin", "a+")));
print "\tPad: " . ($str = $xr->genPad($input));
print "\n\tOutput: " . $xr->encrypt($input, $str) .
"\n\n";
}
*/
?>
PHP now breaks at:
" chr ( $i % $buffer ) ",
in:
if ( strlen( $o ) <= $buffer + 20 ) print "Writing buffer " . chr ( $i %
$buffer ) . "\n" and fwrite( $fo, $o ) and $o = null;
while $I = 5k ± 2k.
Tested within CLI on Windows, I don't think, it'll break on Linux, nor
Apple.
--
(c) Kenan Sulayman
Freelance Designer and Programmer
Life's Live Poetry
Kenan R Sulayman wrote:
Hey Folks!
I've been writing some code for a small project and saw PHP crashing every
time.
Please test the latest snapshot from http://snaps.php.net/. If the problem
still exists, log a bug at http://bugs.php.net/ with version and platform details.
--
Email: christopher.jones@oracle.com Tel: +1 650 506 8630
Twitter: http://twitter.com/ghrd Free PHP Book: http://tinyurl.com/UGPOM
Hello Christopher!
It crashes now at $i = 40k ± 5k, while ( 5k ~ 0.5 second ).
Rather ugly, isn't it ?
Thanks,
(c) Kenan Sulayman
Freelance Designer and Programmer
Life's Live Poetry
2009/3/2 Christopher Jones christopher.jones@oracle.com
Kenan R Sulayman wrote:
Hey Folks!
I've been writing some code for a small project and saw PHP crashing every
time.Please test the latest snapshot from http://snaps.php.net/. If the
problem
still exists, log a bug at http://bugs.php.net/ with version and platform
details.--
Email: christopher.jones@oracle.com Tel: +1 650 506 8630
Twitter: http://twitter.com/ghrd Free PHP Book:
http://tinyurl.com/UGPOM
Additional notice:
After several test, I think, it may be the Windows Command line which
breaks, ( and not the PHP-CLI ).
--
(c) Kenan Sulayman
Freelance Designer and Programmer
Life's Live Poetry
2009/3/2 Kenan R Sulayman kureal@kkooporation.de
Hello Christopher!
It crashes now at $i = 40k ± 5k, while ( 5k ~ 0.5 second ).
Rather ugly, isn't it ?Thanks,
(c) Kenan Sulayman
Freelance Designer and ProgrammerLife's Live Poetry
2009/3/2 Christopher Jones christopher.jones@oracle.com
Kenan R Sulayman wrote:
Hey Folks!
I've been writing some code for a small project and saw PHP crashing
every
time.Please test the latest snapshot from http://snaps.php.net/. If the
problem
still exists, log a bug at http://bugs.php.net/ with version and platform
details.--
Email: christopher.jones@oracle.com Tel: +1 650 506 8630
Twitter: http://twitter.com/ghrd Free PHP Book:
http://tinyurl.com/UGPOM