develooper Front page | perl.beginners | Postings from October 2009

compact my wordlist generator

Thread Next
Michael Alipio
October 25, 2009 01:55
compact my wordlist generator
Message ID:

 I'm trying to write a word list generator which can
 generate all possible combinations of n characters, within n
 set of characters.
 So far, this is what I have come up. The only input is the
 lenght of the password the user wants.
 my @set = qw(a b c d e f g h i j k l m n o p q r s t u v w
 x y z);
 my $len = scalar @set;
 my $char1;
 my $char2;
 my $char3;
 my $char4;
 my $char5;
 my $char6;
 my $char7;
 my $char8;
 if ($pwlen == 8){
 for ($char1=0;$char1<$len;$char1++){
   for ($char2=0;$char2<$len;$char2++){
     for ($char3=0;$char3<$len;$char3++){
     ... upto
     for ($char8=0;$char8<$len;$char8++){
 } elseif ( $pwlen == 7){
 for ($char2=0;$char2<$len;$char1++){
   for ($char3=0;$char3<$len;$char2++){
     for ($char4=0;$char4<$len;$char3++){
     ... upto
     for ($char8=0;$char8<$len;$char8++){
 The problem with the code above is that the length of words
 is hard coded. Only 8 maximum. I'm looking for ways on how
 to make my code flexible (length can be whatever the user
 wants ).
 My code is limited to 8 chars maximum length plus if I want
 to increase it, I have to add another set of for loops plus
 another variable to use, e.g., $char9, char10.. and so
 Any idea?

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About