in reply to Re: Brute Force Algorithm with Perl reg exprs?
in thread Brute Force Algorithm with Perl reg exprs?

Everytime I post here I'm absolutely astounded by the depth of the feedback - many thanks again to everyone who replied - ya'll got some good karma headed your way.

I was looking to build a recursive subroutine that given a $gss and $hint of arbitrary length, and given a @set of valid characters, could generate a @list of all possibilities (without overflowing the call stack) but I think now that I'm probably overthinking the problem (or at least being overly ambitious given my time limitations) - since I know the max length of the password (6 chars) I should probably just hack it using one of the methods described in the replies above...

Thank you much Monks!
  • Comment on Re^2: Brute Force Algorithm with Perl reg exprs?

Replies are listed 'Best First'.
Re^3: Brute Force Algorithm with Perl reg exprs?
by mantadin (Beadle) on Apr 25, 2006 at 07:47 UTC
    This might be a possible solution
    #!/usr/bin/perl -w use strict; my $hint = '1234'; my @chars = ('0'..'9', 'a'..'z'); my $len = 6 - length $hint; &append (""); sub append { my $s = shift; if (length $s >= $len) { &hint($s); return; } foreach (@chars) { my $new = $s.$_; &append ($new); } } sub hint { my $s = shift; my $new; for (my $i=0; $i<=length($s); ++$i) { $s =~ m/^(.{$i})(.*)$/; $new = $1.$hint.$2; print $new."\n"; } }
    But for larger password sizes, this could fill the call stack, so, as long as you know the exact length of the password, you could get rid of the recursion by hardcoding nested foreach()-loops instead. My first idea, how to do it with flexible password sizes and without recursion, would be to write a code generator that nests the necessary number of foreach()-loops for you, using the password size as a parameter. Maybe this is too complicated but the only thing that comes to my mind at the moment.