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

Reply via email to