public
Last active

  • Download Gist
php XOR speed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/***************
 
Comes from a SO comment
 
@Josh K: This is a little over-the-top: $hash = sha1(sha1($password) ^ $salt);, $hash = sha1($password.$salt); would work just as well in practice (and faster). Also, the only reason I can think of to sha1(microtime()) is to constrain it to something that can fit in your column, and substr(str(microtime()), 0, 160) would work equally well (and faster), although I doubt microtime() gives a > 160 digit number anyway. Of course, you might be intentionally making it slow (so it would take more time to crack), but the performance should at least be mentioned.
 
Question: http://stackoverflow.com/questions/3038136/am-i-supposed-to-store-hashes-for-passwords/3038182#3038182
User: http://stackoverflow.com/users/212555/brendan-long
 
**************/
 
/*
 
1000 in 0.468002796173 XOR
1000 in 0.465842008591 XOR
1000 in 0.466115951538 XOR
1000 in 0.498080968857 CAT
1000 in 0.506876945496 CAT
1000 in 0.500174045563 CAT
 
*/
 
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
 
$start_time = $this->microtime_float();
 
for($i = 0; $i < 100000; $i++)
{
// Change . to ^ to test XOR
$sha = sha1(sha1(microtime()) . sha1(microtime()));
}
 
$end_time = $this->microtime_float();
 
error_log("1000 in " . ($end_time-$start_time));

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.