Solved

fastest method to make a wordlist.

Posted on 2004-10-20
7
292 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

785 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