Solved

fastest method to make a wordlist.

Posted on 2004-10-20
7
307 Views
Last Modified: 2006-11-17
Hi,

1)I want to make a wordlist with all possible words (a-zzzzz ; for example).  (the same as here: http://www.apocalypseonline.com/security/tools/redirect.asp?red_tool=dictmake.zip )
What is the fastest way to do this (I allready made the part which writes to the disk): finding the "next in line" (for example : if you have a the "next" function should give b, if you have zz, it should give aaa).
2)If you do a "typedef special_char char"->you make a type "special_char" which is exactly the same as a char;
and you want tonoverload the operator++ for special_char's, is it also overloaded for char's in that case? If so, what should you do to make that it is only overloaded for special_char's and not for char's ??


Thanks in advance.
0
Comment
Question by:Kappa_Alfa_Kappa
  • 4
  • 3
7 Comments
 
LVL 1

Expert Comment

by:gugario
ID: 12358971
You would have to make a second class if you wanted a separate operator.  Typedefing simply means "this expression now is the same as this other one".  But you don't need overloaded operators for that problem, you could do this:

char increaseChar (char value)
{        
    if  (value != ' z' ) return ( char (value + 1) );
    else return 'a';
}

string getNext ( string current )
{
         int i = current.size()-1;   //start at last
         while ( 1 )
         {
                   if (i == -1) //got to the end, and it's all "a's now"
                   {
                            current = "a" + current;
                            break;
                   }
                   current[i] == increaseChar(current[i]);
                   if (current[i] != 'a')  break;  //you didn't overflow.
           }
           return current;
}
             
             





0
 

Author Comment

by:Kappa_Alfa_Kappa
ID: 12363834
Thanks for your code. I tried it.


/////
#include <windows.h>
#include <iostream>
using namespace std;

char increaseChar (char value);
char * getNext ( char * current );
#define MAXLEN 10
int main(int argc, char* argv[])
{
      char  zz[MAXLEN]="ezze";
      for(int i=0; i<20;i++){
            printf(getNext(zz));
      printf("\n");}
      return 0;
}

char increaseChar (char value)
{        
   if  (value != ' z' ) return ( char (value + 1) );
   else return 'a';
}

char * getNext ( char * current )
{
        int i = strlen(current)-1;   //start at last
        while ( 1 )
        {
                  if (i == -1) //got to the end, and it's all "a's now"
                  {
                           current = "a" ;                                             ;
                           break;
                  }
                  current[i] = increaseChar(current[i]);
                  if (current[i] != 'a')  break;  //you didn't overflow.
          }
          return current;
}
////
but after the "z" it goes to the next in line in ascii->"{" and so on ({|}~&#8962;Çüéâäàåç....).
and when it reaches the last one, the lengthdoesn't increases (doesn't goes from ZZ->AAA)...
I think it has something to do with me replacing the string to char* 's, but I'm not sure....

Thaks again for your help.
0
 

Author Comment

by:Kappa_Alfa_Kappa
ID: 12364135
found it:
it works like that:
////////////
char increaseChar (char value)
{        
   if  (value != 'z' ) return ( char (value + 1) );
   else return 'a';
}

char * getNext ( char * current )
{int k;
        int i =k= strlen(current)-1;   //start at last
        while(1){  


        current[i] = increaseChar(current[i]);
                  if (current[i] == 'a')
                              {      i--;
                                    if(i==-1)
                                          {current[k+1]='a';
                                          }
                              }
                          else break;  
            }
          return current;
}
//////////
Do you happen to see severe errors??? (I'm only a beginner).

Thanks.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Kappa_Alfa_Kappa
ID: 12364354
hmmm.... sorry but it was wrong after all.
here is my current code:
/////

char * getNext ( char * current )
{int k;
        int i =k= strlen(current)-1;  

        while(1){  
        current[i] = increaseChar(current[i]);
                  if (current[i] == 'a')
                              {      i--;
                                    if(i==-1)
                                          {current[k+1]='z';
                                          i=strlen(current)-1;
                                          }
                              }
                          else break;  
            }
          return current;
}
//////
which gives:
....  x       y       z       ba      bb      bc ....
.... zy      zz      aba     abb     abc     abd ....

Do you know what is wrong with it ??

Thanks.
0
 
LVL 1

Expert Comment

by:gugario
ID: 12364775
i'm taking a look right now... i'll get back to you shortly!
0
 
LVL 1

Accepted Solution

by:
gugario earned 125 total points
ID: 12365157
Ok, that's not too bad...
change:
                           if(i==-1)
                                   {current[k+1]='z';
                                   i=strlen(current)-1;
                                   }
to:
                            if(i==-1)
                                   {current[k+1]='a';
                                   break;
                                   }

Do you understand why?  For instance, if the initial string was 'zzz', by the time it gets to i = -1, it would be 'aaa', so all we do is add the extra 'a' to the end, and we get "aaaa"....
0
 

Author Comment

by:Kappa_Alfa_Kappa
ID: 12367051
That works indeed. When I see it I understand why ( If I do it really slow with an example...).

Thanks a lot for all your help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Writing a parser for java language 4 91
computer science syllabus 3 100
FMX TCameraComponent Problem 2 92
trigs fail! I thought I knew how to do trignometry 3 82
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question