Re: note 96921 added to function.mt-srand

From: Date: Tue, 23 Mar 2010 14:31:51 +0000
Subject: Re: note 96921 added to function.mt-srand
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-167317@lists.php.net to get a copy of this message
With regard to the word-wrapping, what browser are you using? On Tue, Mar 23, 2010 at 07:56, <dev@10e12.net> wrote: > What about this for an example... > > (sorry for the funky line breaks but I have once > more reported the bug on this issue of word > wrapping to no avail) > > Intending to use it in passing a "semi-guaranteed" > properly seeded random number to a client, then to > capture input from the user which must be encrypted > client side before being sent to the server again >  a) during the same session and, >  b) within a set time limit. > > for more reading also see: >  AES Rijndael enc/dec routines for javaScript >  developed and tested by Herbert Hanewinkel, >  http://www.hanewin.net/encrypt/aes/aes.htm > > <?php > /* > calling the function, prepping the data to send to > the client... , who then uses it in a javascript > implementation of AES Encrypt. > */ > > function SHA256($str, $keyval=""){ >    if ($keyval!==""){//not null or empty >        $sHash = mhash(Constant('MHASH_SHA256'),$str, $keyval); >    }else{ >        $sHash = mhash(Constant('MHASH_SHA256'),$str); >    } >    // same as Binary 2 Hex conversion >    return implode(unpack('H*',$sHash),''); > } > > /*--------------------------------------------------- > Radomizing the random data with fixed data for > the user and location If return value maximum > is set to zero (0) the function uses mt_getrandmax > If both retMin and retMax is zero (0) the function > uses mt_rand w.o. limits > *----------------------------------------------------*/ > function local_prgn($retMin = 0, $retMax = 0){ > // first get the session id of the request session >  $sSrv = session_id(); > > // the following is valid only on the current server >  $sSrv = implode(unpack($_SERVER['SERVER_NAME']. >             $_SERVER['SERVER_ADDR'].$sSrv),''); > > // the following applies only to the requesting client >  $sReq = implode(unpack($_SERVER['REMOTE_ADDR']. >             $_SERVER['REQUEST_TIME']),''); > > // get a SHA256 seed based on the current values >  $sSeed = SHA256($sSrv,$sReq); > > // get a random value based on the uniqueness of the seed above >    mt_srand($sSeed); // seed the random num gen > > // some error handling and checking >    if ($retMin > $retMax){ >    // swap vars if wrong order >        $rx = $retMax; $retMax = $retMin; $retMin = $rx; > >    } else if ($retMin == $retMax){ >    //meaningless range, not very random >    //ensure for next check in this range >        $retMin = 0; $retMax = 0; >    } > // select what we need to return >    if ((($retMax == 0)&&($retMax = mt_getrandmax))|| > ($retMin==$retMax)){ >        return mt_getrandmax(); >    }else{ >        return mt_getrandmax($retMin,$retMax); >    } > } > > ?> > ---- > Server IP: 80.67.10.226 > Probable Submitter: 212.181.164.190 > ---- > Manual Page -- > http://www.php.net/manual/en/function.mt-srand.php > Edit        -- https://master.php.net/note/edit/96921 > Del: integrated  -- > https://master.php.net/note/delete/96921/integrated > Del: useless     -- > https://master.php.net/note/delete/96921/useless > Del: bad code    -- > https://master.php.net/note/delete/96921/bad+code > Del: spam        -- > https://master.php.net/note/delete/96921/spam > Del: non-english -- > https://master.php.net/note/delete/96921/non-english > Del: in docs     -- https://master.php.net/note/delete/96921/in+docs¿ > !ª˜í‰ÊK > Del: other reasons-- https://master.php.net/note/delete/96921 > Reject      -- https://master.php.net/note/reject/96921 > Search      -- https://master.php.net/manage/user-notes.php > > > -- > PHP Notes Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- </Daniel P. Brown> daniel.brown@parasane.net || danbrown@php.net http://www.parasane.net/ || http://www.pilotpig.net/ Looking for hosting or dedicated servers? Ask me how we can fit your budget!

« previous php.notes (#167317) next »