Jump to content

try every possibility


aebstract

Recommended Posts

Sounds like a hacking attempt to me.

 

The algorithm is relatively simple to brute force. Youve got a loop for each digit each subsequent layer is then nested then you just loop while > 10 for each loop.

Link to comment
Share on other sites

Simple bruteforce script

 

 

<?php

function brute ($c, $l, $p = FALSE) {

  foreach ($c as $chr) {
    $pre = $p . $chr;
    if ($l > 1)
      brute($c, $l - 1, $pre);
    else
      echo $pre . "<br>\n";
  }

}

$charset = array('a', 'b', 'c', 'd', 'e', 'f');

brute($charset, 5);

?>

 

Have fun, don't get in trouble :D

Link to comment
Share on other sites

Well I actually got what I needed and did state exactly what I was needing, just didn't say what it was for. Anyhow, with this, is there an easy way to make it group in two doubles and do something such as:

aaaaaa

aaaabb

aaaacc

bbaaaa

bbaabb

 

etc, in doubles versus each letter individually? Of course keeping those doubles the same character.

Link to comment
Share on other sites

I'll explain it modified

 

<?php

// $c is an array, with every string you want to loop through
// $l is the length of the string
// $p is a 'prefix' for fruther calls, and will be explained later

function brute ($c, $l, $p = FALSE) {
  // loop through strings
  foreach ($c as $chr) {
    // this sets up the prefix... below i will call the function again, and this lets the next call of the function know what this call has parsed
    $pre = $p . $chr;
    // this checks if this is the last string to loop through
    if ($l > 1)
      // calls itself, lowering the length by 1 each time...
      brute($c, $l - 1, $pre);
    else
      // this is the last call, echo it.
      echo $pre . "<br>\n";
  }

}

$charset = array('aa', 'bb', 'cc', 'dd', 'ee', 'ff', '00', '11', '22', '33', '44', '55', '66', '77', '88', '99');

brute($charset, 3);

?>

 

Here's what the function does in english...

 

It's called, and it begins looping through the charset...

It defines the prefix as the the current entry in the charset, in this example, 'aa'.

It checks to see how many characters are left to loop though, in this case, it's 3

Because it's 3, it calls itself again, but decreases the characters left to 2, and defines a prefix variables to 'aa'

It repeats the steps above, the prefix is now 'aaaa' and it calls itself again, characters left is now 1..

It defines the prefix as 'aaaaaa' and because it's the last character left, it does not call itself again, but instead, echo's the prefix.

The foreach loop continues for bb-99 with 'aaaa' as the prefix.

The function ends, and the previous call comes in, and sets the prefix as 'aabb', and because the characters left is now 2 again, it calls itself with 'aabb' as the prefix...

 

And it continues.

 

I don't suggest using this script every time a user wants to see every hex value... but it's great for getting them once, and building a static page that will load much faster ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.