Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43229 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79956 invoked from network); 2 Mar 2009 20:02:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Mar 2009 20:02:23 -0000 Authentication-Results: pb1.pair.com header.from=kkooporation@googlemail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=kkooporation@googlemail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.198.228 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: kkooporation@googlemail.com X-Host-Fingerprint: 209.85.198.228 rv-out-0506.google.com Received: from [209.85.198.228] ([209.85.198.228:63161] helo=rv-out-0506.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 85/45-00495-D4B3CA94 for ; Mon, 02 Mar 2009 15:02:22 -0500 Received: by rv-out-0506.google.com with SMTP id b25so2207973rvf.23 for ; Mon, 02 Mar 2009 12:02:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=tkbV2knDVo8yP59iQpbM5XVWERGudfyeHPmZ6OXmdyk=; b=I/26R7e+7bvc2QXweny8dkGERW26XZPTafvtswzQMunKFC4y/fOUhHu6IoJH7JfjNz 9oofdJcjocvqHnBtKxsxO3fbaxX2c2QeRSkgrw9ZjL11ut1z4LcHRqaUPBzXWeEGAIn+ hdNVX8458aGJ6XzJqDE91yPixG9IQwWiybVlA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; b=ZCQEYiv1xkIbvsBqMaAUULC/QzatNd0pFsj50i4AVT2rOG2oFTQLECSzqFllCWFRPP JP6WdBX76+PRbddrAgHQALNIHL8rrBFRlPCKD28mpEDYhs9STvwlGBwjJpoRUsCgJMBv u6DyCVpC4gh3Vd5oQFTIEw5w/Rb55OSFCiK6o= MIME-Version: 1.0 Sender: kkooporation@googlemail.com Received: by 10.142.109.8 with SMTP id h8mr3183584wfc.73.1236024139137; Mon, 02 Mar 2009 12:02:19 -0800 (PST) Date: Mon, 2 Mar 2009 21:02:19 +0100 X-Google-Sender-Auth: b83783226903ba88 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary=00504502cb2dbf434a0464284bd8 Subject: XOR congruentation breaks PHP From: kureal@kkooporation.de (Kenan R Sulayman) --00504502cb2dbf434a0464284bd8 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hey Folks! I've been writing some code for a small project and saw PHP crashing every time. The Code: write genPad to file ) in bit */ public $buffer =3D 4096; public function encrypt($InputString, $KeyPhrase){ $KeyPhraseLength =3D strlen($KeyPhrase); for ($i =3D 0, $strlen =3D strlen($InputString); $i= < $strlen; $i++) $InputString[$i] =3D chr( ( ord($InputString[$i]) ^ ord( $KeyPhrase[ ( $i % $KeyPhraseLength ) ] ) ) ); return $InputString; } public function genPad ( $input ) { for ( $i =3D 1, $o =3D null, $strlen =3D strlen($in= put); $i <=3D $strlen; ++$i ) $o .=3D chr( mt_rand( 10, 300 ) ); return $o; } public function writePad ( $file, $byte, $buffer =3D false = ) { $fo =3D fopen( $file, "a+"); if ( !$buffer ) $buffer =3D $this -> buffer; if ( $byte < $buffer ) $buffer =3D $byte; for ( $i =3D 1, $o =3D null; $i <=3D $byte; ++$i ) = { $o .=3D chr( mt_rand( 10, 300 ) ); if ( strlen( $o ) <=3D $buffer + 20 ) print "Writing buffer " . chr ( $i = % $buffer ) . "\n" and fwrite( $fo, $o ) and $o =3D null; } } } $xor =3D new XoRb; $xor -> buffer =3D 1024; $xor -> writePad ( 'int.dat', 8192 * 1000 ); /* //Interface while ( true ) { print "Input: "; $input =3D trim(fgets(fopen("php://stdin", "a+"))); print "\tPad: " . ($str =3D $xr->genPad($input)); print "\n\tOutput: " . $xr->encrypt($input, $str) . "\n\n"; } */ ?> PHP now breaks at: " chr ( $i % $buffer ) ", in: if ( strlen( $o ) <=3D $buffer + 20 ) print "Writing buffer " . chr ( $i % $buffer ) . "\n" and fwrite( $fo, $o ) and $o =3D null; while $I =3D 5k =C2=B1 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 --00504502cb2dbf434a0464284bd8--