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.

In reply to Re^3: Brute Force Algorithm with Perl reg exprs? by mantadin
in thread Brute Force Algorithm with Perl reg exprs? by scotchfx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.