Follow us on Twitter!
The measure of a mans life is not how well he dies, but how well he lives.
Thursday, April 24, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 28
Guests Online: 22
Members Online: 6

Registered Members: 82895
Newest Member: kevy90
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

PHP Array comparing help.

fashizzlepop
Member



Posts: 482
Location: Old folks home.
Joined: 08.04.08
Rank:
Moderate
Posted on 18-08-08 22:51
I need help comparing 2 arrays in PHP. I have one array of 5 md5 hashes and 1 array of a md5 hash of every letter a-z A-Z and 1-9 and 0.

I need to take the first array and compare it to the second one so it tells me which letter or number the md5 is from and then echo it. I have tried so many things it seems that the world just doesn't want me to know. I have googled and stuff but am just that 1 step away. here is what I got so far...

Code

foreach ($list1 as $a)
   {
  foreach ($list2 as $b)
      {
           if ($a == $b)
             {
               echo "$b";
             }
       }
   }
?>







"The definition of insanity is doing the same thing over and over again and expecting different results.
~Albert Einstein~


csullivan.codeinspire.net/images/boomsig2.png
fashizzlepop@gmail.com http://csullivan.codeinspire.net/
Author

RE: PHP Array comparing help.


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 18-08-08 22:59
I can't see what's wrong with your code, but I tried this and it worked:

Code

<?php
$list2=array("hash1","hash2","hash3","hash4","hash5");
$list1=array("wrong1","wrong2","wrong3","hash1","hash4");
foreach($list1 as $a)
{
        foreach($list2 as $b)
        {
                if($b==$a)
                {
                        echo "$a\n";
                }
        }
}
?>




It's apparently the same code.

Edit: Maybe I'm not understanding your question right.

Edited by on 18-08-08 23:02
Author

RE: PHP Array comparing help.

Mr_Cheese




Posts: 2468
Location: Brighton, UK
Joined: 30.11.04
Rank:
Uber Elite
Posted on 18-08-08 23:02
that should work.

might want to add a break; in there to save resources.

only problem i can see arrising is if your arrays are like this:

$array['as234ad432asad4343asda43343ad'] = 'a';

then that will cause problems, because you'll be checking the md5 against 'a' instead of another hash.

for that situation use: foreah($array as $name => $value){ }
$name = as234ad432asad4343asda43343ad
$value = a
http://www.hellboundhackers.org/
Author

RE: PHP Array comparing help.

fashizzlepop
Member



Posts: 482
Location: Old folks home.
Joined: 08.04.08
Rank:
Moderate
Posted on 18-08-08 23:20
Hmmm, maybe I didn't turn my array into hashes correctly. Here's my whole code. The point is to take a 160 char long string and break it into 5 md5 hashes. Then compare it to what 5 separate characters generated those 5 hashes.

Code

<?php
$thetext = $_POST['hash'];

$newtext = wordwrap($thetext, 32, ",", true);

$hashes = array(explode(",", $newtext));

function sporks($n)
{

$m = md5($n);

return($m);
}

$hashed = array_map("sporks", $values);


foreach ($hashes as $a)
   {
  foreach ($hashed as $b)
      {
           if ($a == $b)
             {
               echo "$b";
             }
       }
   }
?>





And the POST works fine for sure.


"The definition of insanity is doing the same thing over and over again and expecting different results.
~Albert Einstein~


csullivan.codeinspire.net/images/boomsig2.png
fashizzlepop@gmail.com http://csullivan.codeinspire.net/
Author

RE: PHP Array comparing help.


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 18-08-08 23:28
Uhm, you didn't define $values.

Edit: If you do print_r($hashed), you'll see that it's empty.

Edited by on 18-08-08 23:31
Author

RE: PHP Array comparing help.

fashizzlepop
Member



Posts: 482
Location: Old folks home.
Joined: 08.04.08
Rank:
Moderate
Posted on 18-08-08 23:34
Sorry I forgot to post ALL my code. Here it is...


Code
<?php
$values = array('0','1','2','3','4','5','6','7','8','9','a','A','b','B','c','C','d','D','e','E','f','F','g','G','h','H','i','I','j','J','k','K','l','L','m','M','n','N','o','O','p','P','q','Q','r','R','s','S','t','T','u','U','v','V','w','W','x','X','y','Y','z','Z');

$thetext = $_POST['hash'];

$newtext = wordwrap($thetext, 32, ",", true);

$hashes = array(explode(",", $newtext));

function modeish($n)
{

$m = md5($n);

return($m);
}

$hashed = array_map("modeish", $values);


foreach ($hashes as $a)
   {
  foreach ($hashed as $b)
      {
           if ($a == $b)
             {
               echo "$b";
             }
       }
   }
?>




I had $values up higher at the beggining of the page.


"The definition of insanity is doing the same thing over and over again and expecting different results.
~Albert Einstein~


csullivan.codeinspire.net/images/boomsig2.png
fashizzlepop@gmail.com http://csullivan.codeinspire.net/
Author

RE: PHP Array comparing help.


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 18-08-08 23:46
$hashes is 2-dimensional. I'll see if I can figure out how to make it a 1-dimensional array.

Edit:
Code

<?php
$values = array('0','1','2','3','4','5','6','7','8','9','a','A','b','B','c','C','d','D','e','E','f','F','g','G','h','H','i','I','j','J','k','K','l','L','m','M$
$thetext = $_GET['hash'];

$newtext = wordwrap($thetext, 32, ",", true);
$hashes = explode(",", $newtext);

function modeish($n)
{

$m = md5($n);

return($m);
}

$hashed = array_map("modeish", $values);
foreach ($hashes as $a)
{
foreach ($hashed as $b)
{
if ($a == $b)
{
echo "$b";
}
}
}
?>





That should work.

Edited by on 18-08-08 23:49
Author

RE: PHP Array comparing help.

fashizzlepop
Member



Posts: 482
Location: Old folks home.
Joined: 08.04.08
Rank:
Moderate
Posted on 18-08-08 23:56
Heres my new code and here is my error...

Code
<?php
$values = array('0','1','2','3','4','5','6','7','8','9','a','A','b','B','c','C','d','D','e','E','f','F','g','G','h','H','i','I','j','J','k','K','l','L','m','M$
$thetext = $_GET['hash'];

$newtext = wordwrap($thetext, 32, ",", true);
$hashes = explode(",", $newtext);

function modeish($n)
{

$m = md5($n);

return($m);
}

$hashed = array_map("modeish", $values);
foreach ($hashes as $a)
{
foreach ($hashed as $b)
{
if ($a == $b)
{
echo "$b";
}
}
}
?>




Parse error: syntax error, unexpected T_STRING, expecting ')' in /home/mouncerc/public_html/fashizzlepop/challenge.php on line 21


"The definition of insanity is doing the same thing over and over again and expecting different results.
~Albert Einstein~


csullivan.codeinspire.net/images/boomsig2.png
fashizzlepop@gmail.com http://csullivan.codeinspire.net/
Author

RE: PHP Array comparing help.

spyware
Member



Posts: 4192
Location:
Joined: 14.04.07
Rank:
God
Warn Level: 90
Posted on 18-08-08 23:58
Check $values = array and use a syntax highlighting editor (like Notepad++ if using Windows).



img507.imageshack.us/img507/3580/spynewsig3il1.png
"The chowner of property." - Zeph
[small]
Widespread intellectual and moral docility may be convenient for leaders in the short term,
but it is suicidal for nations in the long term.
- Carl Sagan
[center]�Since the grid is inescapable, what were the earlier lasers about? Does the corridor have a sense of humor?� - Ebert[/ce
Author

RE: PHP Array comparing help.


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 19-08-08 00:00
Sorry, I copied it from nano, the correct code is:
Code

<?php
$values = array('0','1','2','3','4','5','6','7','8','9','a','A','b','B','c','C','d','D','e','E','f','F','g','G','h','H','i','I','j','J','k','K','l','L','m','M','n','N','o','O','p','P','q','Q','r','R','s','S','t','T','u','U','v','V','w','W','x','X','y','Y','z','Z');

$thetext = $_GET['hash'];

$newtext = wordwrap($thetext, 32, ",", true);
$hashes = explode(",", $newtext);

function modeish($n)
{

$m = md5($n);

return($m);
}

$hashed = array_map("modeish", $values);
foreach ($hashes as $a)
{
foreach ($hashed as $b)
{
if ($a == $b)
{
echo "$b";
}
}
}
?>





(The $ is because it went on farther than the width of the screen)

Edited by on 19-08-08 00:00
Author

RE: PHP Array comparing help.

fashizzlepop
Member



Posts: 482
Location: Old folks home.
Joined: 08.04.08
Rank:
Moderate
Posted on 19-08-08 20:24
I copied that code exactly and nothing gets displayed... Sad

I have no idea whats wrong. There isn't a error.


"The definition of insanity is doing the same thing over and over again and expecting different results.
~Albert Einstein~


csullivan.codeinspire.net/images/boomsig2.png
fashizzlepop@gmail.com http://csullivan.codeinspire.net/
Author

RE: PHP Array comparing help.

Mr_Cheese




Posts: 2468
Location: Brighton, UK
Joined: 30.11.04
Rank:
Uber Elite
Posted on 19-08-08 20:39
print_r your arrays, so we can actually see and try and help.

i reakon its a $name => $var problem like i mentioned above.
http://www.hellboundhackers.org/
Author

RE: PHP Array comparing help.


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 19-08-08 21:13
[CODE]
<?php
$values = array('0','1','2','3','4','5','6','7','8','9','a','A','b','B','c','C','d','D','e','E','f','F','g','G','h','H','i','I','j','J','k','K','l','L','m','M','n','N','o','O','p','P','q','Q','r','R','s','S','t','T','u','U','v','V','w','W','x','X','y','Y','z','Z');

$thetext = $_GET['hash'];

$newtext = wordwrap($thetext, 32, ",", true);
$hashes = explode(",", $newtext);

function modeish($n)
{

$m = md5($n);

return($m);
}
echo '$hashes: ';
print_r($hashes);
echo "<br /><br />";
$hashed = array_map("modeish", $values);
echo '$hashed: ';
print_r($hashed);
echo "<br /><br />";
foreach ($hashes as $a)
{
foreach ($hashed as $b)
{
if ($a == $b)
{
echo "$b<br />";
}
}
}
?>[/CODE]

That displays http://jonnycake.. . .45e841ec32


Edited by on 19-08-08 21:14
Author

RE: PHP Array comparing help.

fashizzlepop
Member



Posts: 482
Location: Old folks home.
Joined: 08.04.08
Rank:
Moderate
Posted on 24-08-08 23:47
Ok hmm, I wonder why it wasn't working for me... but now I just realized I need to reformat it differently... Thanks for the help!!!


"The definition of insanity is doing the same thing over and over again and expecting different results.
~Albert Einstein~


csullivan.codeinspire.net/images/boomsig2.png
fashizzlepop@gmail.com http://csullivan.codeinspire.net/