Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Re: brute force (http://www.velocityreviews.com/forums/t276988-re-brute-force.html)

David List 08-22-2003 12:36 PM

Re: brute force
 
On Fri, 22 Aug 2003 14:40:51 +0300,
rosty <nezeii@hotmail.com>
wrote in <bi4vce$591i2$2@ID-170362.news.uni-berlin.de>:
> does anybody know how a brute force algorithm looks like? the result should
> be something like this a, b, c; etc then aa, ab, ac; etc and so on....
> i imagine there should be a vector of char holding the chars that are going
> to participate in the brute forcing,
> vector<char> vc(3);
> vc[0]='a';
> vc[1]='b';
> vc[2]='c';//only three char for simplicity
>
> then a string that is going to be the pass itself. then an iteration
> through the vector and adding those chars to the pass string, and an int
> holding the actual size of the pass (untill the pass reaches its maximum)
> and then... i just cannot put it all together, is it so difficult, or am i
> just so stupid?
> any code example?


I think some sort of permutation algorithm could help you out
here. Luckily there is a built-in function for that in C++. Try
looking into the next_permutation() function in <algorithm>. If you
have Stroustrup, 3rd edition, he mentions it in section 18.10.

--
Med venlig hilsen / Best regards
David List

rosty 08-22-2003 01:15 PM

Re: brute force
 
thanks, but next_permutaion() and prev_permutaion() are usefull ( imho) only
if you have a fixed length string and wish to have all possible combinations
of the chars within that string.
like it says in the book:
abcd abdc acbd acdb etc....

the pass string for the brute force is:
1) of an alterable length
2) is made from a series of chars usually larger than the resulting string

i'm still puzzled, and btw, i made of course a google search and the only
thing i found was people claiming it is simple, but never saw a piece of
code proving that, maybe it is simple but i'm really puzzled


"David List" <david@davidlist.dk> wrote in message
news:rbfh11-s1s.ln1@initio.dk...
> On Fri, 22 Aug 2003 14:40:51 +0300,
> rosty <nezeii@hotmail.com>
> wrote in <bi4vce$591i2$2@ID-170362.news.uni-berlin.de>:
> > does anybody know how a brute force algorithm looks like? the result

should
> > be something like this a, b, c; etc then aa, ab, ac; etc and so on....
> > i imagine there should be a vector of char holding the chars that are

going
> > to participate in the brute forcing,
> > vector<char> vc(3);
> > vc[0]='a';
> > vc[1]='b';
> > vc[2]='c';//only three char for simplicity
> >
> > then a string that is going to be the pass itself. then an iteration
> > through the vector and adding those chars to the pass string, and an int
> > holding the actual size of the pass (untill the pass reaches its

maximum)
> > and then... i just cannot put it all together, is it so difficult, or am

i
> > just so stupid?
> > any code example?

>
> I think some sort of permutation algorithm could help you out
> here. Luckily there is a built-in function for that in C++. Try
> looking into the next_permutation() function in <algorithm>. If you
> have Stroustrup, 3rd edition, he mentions it in section 18.10.
>
> --
> Med venlig hilsen / Best regards
> David List




Jeremy Cowles 08-22-2003 01:34 PM

Re: brute force
 
> thanks, but next_permutaion() and prev_permutaion() are usefull ( imho)
only
> if you have a fixed length string and wish to have all possible

combinations
> of the chars within that string.


But that is good for you, because you are dealing with a fixed-length set
for each iteration. Look:

set width = 1) a, b, c...
set width = 2) aa, ab, ac, ad
set width = 3) aaa, aab, aac

You see?

Or are you looking for the BruteForce object? Or perhaps the
BruteForceForNT object? Well you won't find them. You can't avoid writing
some code for your self.

~
Jeremy


Jeremy Cowles 08-22-2003 03:01 PM

Re: brute force
 
If you know VB, I have a class that does what you want. Given a specific
character set, and a result width, it produces every possible combonation of
the character set in the specified width, similar to next/prev_permutation.
Let me know if you want me to post it.


~
Jeremy


Karl Heinz Buchegger 08-22-2003 03:59 PM

Re: brute force
 


rosty wrote:
>
> thanks, but next_permutaion() and prev_permutaion() are usefull ( imho) only
> if you have a fixed length string and wish to have all possible combinations
> of the chars within that string.
> like it says in the book:
> abcd abdc acbd acdb etc....
>
> the pass string for the brute force is:
> 1) of an alterable length
> 2) is made from a series of chars usually larger than the resulting string
>
> i'm still puzzled, and btw, i made of course a google search and the only
> thing i found was people claiming it is simple, but never saw a piece of
> code proving that, maybe it is simple but i'm really puzzled


If I understood your problem correctly, then it is indeed simple. It
is a recursive function.

What do you want:

You have a string (initially empty)
From this string you create new strings
by adding a character. This will give a
new string where you have to do the same procedure

void AddTo( std::string orig )
{
std::string new_a = orig + 'a';
std::cout << new_a << "\n";

AddTo( new_a );
}

The above will create the sequence
"a" "aa" "aaa" "aaaa" etc.

Exercises left for the reader:
replace the 'fixed' set of letters to add (in the above case
'a') with a variable set (your vector, you will need a loop)

Add a termination criterium, such that the whole thing stops
when a specific amount of letters have been added (Hint:
pass the nesting level as an additional parameter and increment
it by each recursive function call).

Don't output the created strings, but store them in a vector.

--
Karl Heinz Buchegger
kbuchegg@gascad.at


All times are GMT. The time now is 09:57 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.