Jump to content

discomatt

Members
  • Posts

    1,943
  • Joined

  • Last visited

    Never

Posts posted by discomatt

  1. I'll send you $50 over PayPal if you tell me what the what the plaintext value I used for this hash is:

    9f65f29197e64cef1f862f359866c3abdc473da40a0efd1f6bca32fb13cfb5da

    It's not enough finding a string that matches the hash. You must prove that what you got is the same as what I originally had. Anyone else who wants to try can claim the $50 as well.

     

    May I have 5.2^114 guesses?

  2. I've always liked this method:

     

    Generate random salt ( usually of the same length as the hash )

     

    Chop the password and salt into 2 chunks.

     

    Mix chunks and hash.

     

    Split hash into 2 parts, mix with salt.

     

    You now have the salt stored in plain text, but it's theoretically impossible to extract it from the hash without knowing the chunk sizes and algorithm used. It's a little paranoid, but it's actually a very light script ( php is very quick and string manip ) requiring only 1 hash to check a password.

     

    Salting is VERY VERY important. I would argue a random salt is equally important. You're protecting your viewers passwords they might use elsewhere. Rainbow tables are becoming huge and easy to access.

  3. That's another neat concept, but that one is a hog, running about 10x slower than our previous functions using realistic depth, and nearly 15x slower than mine on unrealistic depths.

     

    I think I'm going to stick with either your or my original function, pending a little more speed testing.

     

    Thanks again for the time and thought, and helping me look outside the box :D

  4. Here's a working example of what I'm doing on a broader scope

     

    <pre><?php
    
    /*
    
    1		67
    20		107
    43		116
    77		153
    125		161
    
    
    
    */
    
    $data = <<<DATA
    {loop}
    Some data
    {loop}
    	Nested data
    	{loop}
    		More nests!
    	{/loop}
    	{loop}
    		Another deep nest
    	{/loop}
    {/loop}
    {loop}
    	Not quite so deep
    {/loop}
    {/loop}
    {loop}
    More data
    {loop}
    	Foobar
    {/loop}
    {loop}
    	Warmer
    	{loop}
    		Waaaarmer
    		{loop}
    			Too hot!
    		{/loop}
    	{/loop}
    {/loop}
    {loop}
    	More depth
    	{loop}
    		this is getting stupid
    	{/loop}
    {/loop}
    {/loop}
    DATA;
    
    $pairs = getPairs($data, '{loop}', '{/loop}');
    
    foreach( $pairs as $pair )
    echo substr( $data, $pair[0], $pair[1]-$pair[0] ) . "\n\n\n--------\n\n\n";
    
    function getPairs( $data, $openTag, $closeTag ) {
    
    // Grab opening and closing offsets
    $opening = getOffsets( $data, $openTag );
    $closing = getOffsets( $data, $closeTag, FALSE );
    
    // Verify proper formatting
    if( ($size = count($opening)) !== count($closing) )
    			die( "Invalid syntax detected" );
    
    // Placeholder
    $offsets = array();
    
    // Separate nests
    for( $i = 1; $i < $size; $i++ ) {
    
    	// Set initial nest key
    	static $last = 0;
    	// Check to see if a new nest has begun
    	if( isset($opening[$i+1]) === FALSE || $opening[$i+1] > $closing[$i] ) {
    		// Send nest to parser and gather results
    		$offsets = array_merge( $offsets, parseNest(array_slice($opening,$last,$i-$last+1), array_slice($closing,$last,$i-$last+1)) );
    		// Update nest key to the start of the next nest
    		$last = $i+1;
    
    	}
    
    }
    
    return $offsets;
    
    }
    
    function getOffsets( $data, $tag, $open = TRUE ) {
    
    // Placeholder
    $return = array();
    
    // Start at beginning of string
    $offset = 0;
    
    // Loop through string grabbing offsets
    while( ($c = strpos($data, $tag, $offset)) !== FALSE ) {
    	// Update search offset
    	$offset = strpos( $data, $tag, $c ) + 1;
    	// Remove tag offset and add to placeholder
    	$return[] = $offset - 1 + ( $open == TRUE ? strlen($tag) : -1 );
    }
    
    return $return;
    
    }
    
    function parseNest( $opening, $closing ) {
    
    // Placeholder
    $pairs = array();
    
    // Loop through $opening backwards
    foreach( array_reverse($opening) as $oVal ) {
    
    	/***** THIS IS THE CHUNK I THINK CAN BE IMPROVED ON *****/
    
    	// Loop through $closing until we find a value less than the current $opening
    	foreach( $closing as $cKey => $cVal )
    		// Check to see if the current opening is less than the current closing
    		if( $oVal < $cVal ) {
    			// If so, add it to the pairs
    			$pairs[] = array( $oVal, $cVal );
    			// Unset used value of b - prevents duplication and should speed things up
    			unset( $closing[$cKey] );
    			// Break out of the loop
    			break;
    		}
    
    	/***** END OF CHUNK *****/
    
    }
    
    // Return them in ascending order
    return array_reverse( $pairs );
    
    }
    
    ?></pre>

  5. Okay, let me expand on this.

     

    It's a function to match up nested pairs of strings. Array $a would be the offsets for opening tags, while array $b would be the offsets of closing tags.

     

    bobbinsbro : The arrays will/should always be in ascending order... and if it wasn't, I can always use sort() before looping.

     

    sasa: Yes, they should both be in ascending order at all times.

     

    corbin: It's part of the algorithm. In order to find the correct matching pairs, it takes the least amount of work to start from the opening end ( deepest element ) and work your way up/out.

     

    Just to clear things up, here's what I'm doing, in a wider scope. This is a crude example... the actual code I'm using is nested in a class with a ton of erroneous garbage so I shortened it up

     

    [edit] oops, gotta clean a few things up before i can provide an example [/edit]

     

    Thanks for your replies thus far :D

  6. Well, if you want to follow PHP's function naming spec.

     

    '/[a-z_\x7f-\xff][a-z0-9_\x7f-\xff]++\([^)]++\)/i'

     

    This is assuming you won't use literal strings with closing brackets in your function... for example

     

    bleh('Stuff with a ) closing bracket')

     

    If you want something like that, the expression becomes quite a bit more complex :)

  7. First I'll try to explain the problem.

     

    I have 2 arrays of identical size, similar to the example below

    $a = array( 2, 29, 54, 77 );
    $b = array( 66, 72, 102, 107 );

     

    I want to go through each value of $a in reverse, and find the lowest value of $b that is greater than the current value of $a. To add to this mess, I don't want to reuse any values of $b when pairing them with values from $a

     

    Here's what I've got so far

     

    <pre><?php
    
    $a = array( 2, 29, 54, 77 );
    $b = array( 66, 72, 102, 107 );
    
    // Placeholder for found pairs
    $pairs = array();
    
    
    // Loop through $a backwards
    foreach( array_reverse($a) as $aVal ) {
    
    /***** THIS IS THE CHUNK I THINK CAN BE IMPROVED ON *****/
    
    // Loop through $b until we find a value less than the current $a
    foreach( $b as $bKey => $bVal )
    	// Check to see if the current value of b is less than the current value of a
    	if( $aVal < $bVal ) {
    		// If so, add it to the pairs
    		$pairs[] = array( $aVal, $bVal );
    		// Unset used value of b - prevents duplication and should speed things up
    		unset( $b[$bKey] );
    		// Break out of the loop
    		break;
    	}
    
    /***** END OF CHUNK *****/
    
    }
    
    print_r( $pairs );
    
    ?></pre>

     

    The output should look like this

     

    Array
    (
        [0] => Array
            (
                [0] => 77
                [1] => 102
            )
    
        [1] => Array
            (
                [0] => 54
                [1] => 66
            )
    
        [2] => Array
            (
                [0] => 29
                [1] => 72
            )
    
        [3] => Array
            (
                [0] => 2
                [1] => 107
            )
    
    )
    

     

    Any help is greatly appreciated. I'm hoping there's some cool array trick I just don't know about.

     

    Thanks for lookin'

  8. I'd do something like this:

     

    <?php
    
    $code = <<<CODE
      some content
      goes here
    <?php
    
    morePHPcode();
    
    while ( !($succeed = try()) );
    
    echo 'foo'.\$bar;
    
    ?>
    here's some <b>more</b> content, ect. ect.
    CODE;
    
    echo hiliteCode( $code );
    
    function hiliteCode( $input ) {
    
    $regex = '/<\?.*?\?>/s';
    return preg_replace_callback(
    	$regex,
    	create_function(
    		'$m',
    		'return "<pre>".highlight_string( $m[0], TRUE )."</pre>";'
    	),
    	$input
    );
    
    }
    
    ?>

  9. I think i see what you mean... try this guy

     

    <pre><?php
    
    $subject = 'The cat sat on the [[straw|mat]].
    The cat hoped he would jump through the [[windows]] and catch the [[feathered variety|bird on the branch]].';
    
    $array = getValues( $subject );
    
    print_r( $array );
    
    function getValues( $input ) {
    
    $regex = '/\[\[([^|\]]++)(?:\|([^\]]++)){0,1}/';
    if( preg_match_all($regex, $input, $matches, PREG_SET_ORDER) < 1 )
    	return array();
    
    $return = array();
    foreach( $matches as $m ) {
    	if( isset($m[2]) === FALSE )
    		$return[] = $m[1];
    	else
    		$return[] = $m[2];
    }
    return $return;
    
    }
    
    ?></pre>

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.