iterating over arrays with map - problem
From: Mothra (mothra_at_mothra.com)
Date: 05/19/04
- Next message: Mothra: "Re: Perl Patten Matching and Data Extraction"
- Previous message: Mark Fletcher: "Re: How to use backreferences in a variable for a regular expression"
- Next in thread: ! aaa: "Re: iterating over arrays with map - problem"
- Reply: ! aaa: "Re: iterating over arrays with map - problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 19 May 2004 11:46:08 GMT
Trying (just for fun) to write my own Perl version of 'Crack' but am
stumbling a bit trying to iterate over my dictionary file to generate
possible passwords. When I run the code below with "dictionary.txt"
containing the single word "password", I get around 4,000 entries, most
of which are identical, even though on most occassions there is no
subsitution to be made.
I tried using next in the map block, but it won't let me. What I would
like it to generate (for each word in the dictionary file) all possible
letter/number substitution combinations, that is, not to simply
accumulate changes, but nor to needlessly repeat them either.
The best I can get is either:
password
p4ssword
p455word
p455w0rd
which is useless; the only other result I get is thousands of redundant
entries.
What is the more efficient way I should be writing this (see below)?
---------------------------------
sub init_dictionary {
open(DICT,"dictionary.txt");
chomp(@dict=<DICT>);
close DICT;
push @dict, map { s/[aA]/4/g;$_ } @dict;
push @dict, map { s/[bB]/8/g;$_ } @dict;
push @dict, map { s/[eE]/3/g;$_ } @dict;
push @dict, map { s/[gG]/6/g;$_ } @dict;
push @dict, map { s/[iI]/1/g;$_ } @dict;
push @dict, map { s/[lL]/1/g;$_ } @dict;
push @dict, map { s/[oO]/0/g;$_ } @dict;
push @dict, map { s/[sS]/5/g;$_ } @dict;
push @dict, map { s/[tT]/7/g;$_ } @dict;
push @dict, map { s/[zZ]/2/g;$_ } @dict;
}
- Next message: Mothra: "Re: Perl Patten Matching and Data Extraction"
- Previous message: Mark Fletcher: "Re: How to use backreferences in a variable for a regular expression"
- Next in thread: ! aaa: "Re: iterating over arrays with map - problem"
- Reply: ! aaa: "Re: iterating over arrays with map - problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|