Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

fastest method to make a wordlist.

Posted on 2004-10-20
7
300 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

808 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