You are here: Re: [Help] Brute Force « All PHP « IT news, forums, messages
Re: [Help] Brute Force

Posted by Lόpher Cypher on 01/01/06 13:52

Daemon wrote:
> Hello,
>
> I am trying to create a script that will create a loop threw ascii
> characters 32 - 126, but be limited to the number in a varible,
> controlling how many returns. I figgured a control of how many array
> keys would be a good spot, say I only want strings that start with 3
> characters and end at 5 charcters.
>
> And I wanted to use an array for all possible ascii characters. So far,
> the code I have is a bit of a mess and was hoping for some one that has
> more knowledge in php to lead me in the right direction to how to
> accomplish my task at hand.
>
> <?php
....
> ?>
>

Man, that was some crazy code. :)

Let me see if I understand what you are trying to do. You have
characters with ascii codes 32..126, you want to generate all possible
strings consisting of characters with those codes, whose length is
between some minimum and maximum?
Like, if min=3 and max=5 and restricting to set 'a'..'z', it'd be
aaa, aab, aac, ..., aaz, aba, abb, ..., zzz, aaaa, aaab, ..., zzzz
Right? Then why not use recursion?

$startCode = 32;
$endCode = 126;

function gen(&$resultArray,$min,$max,$parentStr) {
global $startCode,$endCode;
if (strlen($parentStr)+1 >= $min &&
!isset($resultArray[strlen($parentStr)+1])) {
$resultArray[strlen($parentStr)+1] = array();
}
for ($i = $startCode; $i <= $endCode; $i++) {
$str = $parentStr.chr($i);
if (strlen($str) >= $min) {
array_push(&$resultArray[strlen($str)],$str);
}
if (strlen($str) < $max) {
gen(&$resultArray,$min,$max,$str);
}
}
}

function generate($min,$max) {
$resultArray = array();
gen(&$resultArray,$min,$max,"");
return $resultArray;
}

$arr = generate(3,5);
echo "<pre>";print_r($arr);echo "</pre>";


luph

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация