Password generator (limit my dictionary to...)
Hi, I'm trying to create a dictionary file for my bruteforce program. I have a huge dictionary file and I want to trim it down according the requirements. The output should be a dictionary file that is minimum 6 characters and maximum 15 characters with at least 4 letters and 2 numbers in it.. no special characters whatsoever.. This should be a simple regex but it's been a while since i wrote my last regexp program. Need to refresh my perl basics a little bit.. So far I got this: #!/usr/bin/perl use warnings; use strict; my $wordlist = shift @ARGV; #my $newwordlist = shift @ARGV; open INPUTFILE, "$wordlist" or die $!; #open OUTPUTFILE, ">$output" or die $!; while (){ next if !(/\b\w\w\w\w\b/); print; } __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Password generator (limit my dictionary to...)
On Oct 22, 2:45 am, [EMAIL PROTECTED] (Michael Alipio) wrote: > The output should be a dictionary file that is minimum > 6 characters and maximum 15 characters with at least 4 > letters and 2 numbers in it.. no special characters > whatsoever.. This should be a simple regex but it's > been a while since i wrote my last regexp program. > Need to refresh my perl basics a little bit.. Don't fall into the trap of trying to express every one of your requirements as one giant regexp. There's no reason for that. > So far I got this: > > #!/usr/bin/perl > use warnings; > use strict; > > my $wordlist = shift @ARGV; > #my $newwordlist = shift @ARGV; > > open INPUTFILE, "$wordlist" or die $!; > #open OUTPUTFILE, ">$output" or die $!; > > while (){ next unless /^[a-z0-9]{6,15}$/; next unless tr/a-z// >= 4; next unless tr/0-9// >= 2; > print; > } Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Password generator (limit my dictionary to...)
Hi Paul, Here's what I came up with: #!/usr/bin/perl use warnings; use strict; my $wordlist = shift @ARGV; open INPUTFILE, "$wordlist" or die $!; while (){ # Find all words that are 6-15 characters with at least 2 digits and 4 letters that can appear anywhere next unless (/\b\w{6,15}\b\n/ && /.*(\d).*\d/ && /(.*([a-z]|[A-Z]).*){4}/); print; } So far i can say that it is working, however i'm not one 100% sure of it. I'm not really confident about the positioning. I have to put '.*' before and after my main expressions... I'm not sure if i'm doing it right. With a list file that looks like this: abcdefghijklmno 22 abcdef abcd22 1aniraco Abcd22 ABCD22 abc2d2 abc1def2ijklmno 22 abcdef .ask lasdf I have managed to extract these: abcd22 Abcd22 ABCD22 abc2d2 abc1def2ijklmno That is, regardless of the position, it must have at least 4 letters and 2 numbers and of course it should fall between 6 to 15 characters. In the meantime, let me look at your solution... --- Paul Lalli <[EMAIL PROTECTED]> wrote: > On Oct 22, 2:45 am, [EMAIL PROTECTED] (Michael > Alipio) wrote: > > > The output should be a dictionary file that is > minimum > > 6 characters and maximum 15 characters with at > least 4 > > letters and 2 numbers in it.. no special > characters > > whatsoever.. This should be a simple regex but > it's > > been a while since i wrote my last regexp program. > > Need to refresh my perl basics a little bit.. > > Don't fall into the trap of trying to express every > one of your > requirements as one giant regexp. There's no reason > for that. > > > So far I got this: > > > > #!/usr/bin/perl > > use warnings; > > use strict; > > > > my $wordlist = shift @ARGV; > > #my $newwordlist = shift @ARGV; > > > > open INPUTFILE, "$wordlist" or die $!; > > #open OUTPUTFILE, ">$output" or die $!; > > > > while (){ > > next unless /^[a-z0-9]{6,15}$/; > next unless tr/a-z// >= 4; > next unless tr/0-9// >= 2; > > > print; > > } > > > Paul Lalli > > > -- > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > http://learn.perl.org/ > > > __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Password generator (limit my dictionary to...)
On Oct 22, 7:56 am, [EMAIL PROTECTED] (Michael Alipio) wrote: > Here's what I came up with: /\b\w{6,15}\b\n/ && /.*(\d).*\d/ && /(.*([a-z]|[A-Z]).*){4}/) \b is a word boundary. It is simply true at spaces in between word characters and non-word characters. Your regexps do not at all preclude special characters from being in your string. \w is what Perl defines as a "word character". That is letters, numbers, AND underscores. If you don't want underscores, you need to change them to [a-zA-Z0-9] Here is an example of a string that your script would allow: ][|2**9($&!abc_defg it contains between 6 and 15 word characters, followed by a newline it matches "anything, digit, anything, digit" it matches "anything-letter" four times. Not only that, but your solution is simply not well readable. I recommend again that you abandon the illogical desire to contrain yourself to one giant regexp expression. There is no need for such a requirement. Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Password generator (limit my dictionary to...)
Michael Alipio wrote: Here's what I came up with: #!/usr/bin/perl use warnings; use strict; my $wordlist = shift @ARGV; open INPUTFILE, "$wordlist" or die $!; while (){ # Find all words that are 6-15 characters with at least 2 digits and 4 letters that can appear anywhere next unless ( /\b\w{6,15}\b\n/ && - The \w character class includes the underscore character, which is probably why Paul wrote his solution the way he did. Whether this is acceptable or not is up to you. [[:alnum:]] is also available if you prefer it - There is no point in putting \b before \n at the end of your regex as a \w character followed by a newline will necessarily contain a word boundary - You say the word can appear anywhere but you are finding the last word in the line. Surely the entire line should be tested, and any junk that happens to end in a valid string isn't acceptable? /.*(\d).*\d/ && This will match a string containing at least two digits, and capture the first one into $1. Paul warned against using regexes for everything and the tr// character count he proposed is much more concise for your purpose: tr/0-9// >= 2 /(.*([a-z]|[A-Z]).*){4}/); This will match a string that contains at least four alphabetic characters, capture the last of them into $1, and the last of them and everything following into $2. But it's not at all clear either what it does or whether it works. Again, the solution with tr// is much better: tr/a-zA-Z// >= 4 print; } [snip] Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Password generator (limit my dictionary to...)
On 10/22/07, Paul Lalli <[EMAIL PROTECTED]> wrote: > On Oct 22, 2:45 am, [EMAIL PROTECTED] (Michael Alipio) wrote: > > > The output should be a dictionary file that is minimum > > 6 characters and maximum 15 characters with at least 4 > > letters and 2 numbers in it.. no special characters > > whatsoever.. This should be a simple regex but it's > > been a while since i wrote my last regexp program. > > Need to refresh my perl basics a little bit.. > > Don't fall into the trap of trying to express every one of your > requirements as one giant regexp. There's no reason for that. > That said, why prefer next unless /^[[:alnum:]]{6,15}$/; to, say next unless length() >= 6 && length() <=15; -- jay -- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom!
Re: Password generator (limit my dictionary to...)
On Oct 22, 2:18 pm, [EMAIL PROTECTED] (Jay Savage) wrote: > On 10/22/07, Paul Lalli <[EMAIL PROTECTED]> wrote: > > > On Oct 22, 2:45 am, [EMAIL PROTECTED] (Michael Alipio) wrote: > > > > The output should be a dictionary file that is minimum > > > 6 characters and maximum 15 characters with at least 4 > > > letters and 2 numbers in it.. no special characters > > > whatsoever.. This should be a simple regex but it's > > > been a while since i wrote my last regexp program. > > > Need to refresh my perl basics a little bit.. > > > Don't fall into the trap of trying to express every one of your > > requirements as one giant regexp. There's no reason for that. > > That said, why prefer > > next unless /^[[:alnum:]]{6,15}$/; > > to, say > > next unless length() >= 6 && length() <=15; Because the latter requires two calls to length(), and still doesn't insure that all the characters are alpha numerics. Which means you will still need an additonal test of next unless/^[[:alnum:]]+$/; If you have to do that test anyway, it seems a lot simpler to change the + to a {6,15} rather than writing out another two tests. Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Password generator (limit my dictionary to...)
On Sunday 21 October 2007 23:45, Michael Alipio wrote: > Hi, Hello, > I'm trying to create a dictionary file for my > bruteforce program. > > > I have a huge dictionary file and I want to trim it > down according the requirements. > > The output should be a dictionary file that is minimum > 6 characters and maximum 15 characters with at least 4 > letters and 2 numbers in it.. no special characters What do you mean by "special characters"? > whatsoever.. This should be a simple regex but it's > been a while since i wrote my last regexp program. > Need to refresh my perl basics a little bit.. > > > So far I got this: > > #!/usr/bin/perl > use warnings; > use strict; > > > my $wordlist = shift @ARGV; > #my $newwordlist = shift @ARGV; > > open INPUTFILE, "$wordlist" or die $!; > #open OUTPUTFILE, ">$output" or die $!; > > while (){ > next if !(/\b\w\w\w\w\b/); > print; > > } Perhaps something like this [UNTESTED]: #!/usr/bin/perl use warnings; use strict; @ARGV == 2 or die "usage: $0 wordlist newwordlist\n"; my ( $wordlist, $newwordlist ) = @ARGV; open INPUTFILE, '<', $wordlist or die "Cannot open '$wordlist' $!"; #open OUTPUTFILE, '>', $output or die "Cannot open '$output' $!"; while ( ) { next unless /\A[[:alnum:]]{6,15}\z/; next unless tr/a-zA-Z// >= 4; next unless tr/0-9// >= 2 print; } __END__ John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/