Guest User

c++ wordlist generator

a guest
Apr 17th, 2010
1,333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <cstring>
  5. #include <cstdlib>
  6.  
  7. int number_of_chars;
  8. char chars_to_use[200];
  9.  
  10. using namespace std;
  11.  
  12. ofstream out;
  13.  
  14. void outputcout(string x, int number_of_chars_left, string separator) {
  15.  
  16.     char c;
  17.        
  18.     if(number_of_chars_left==0) {
  19.         cout << x << separator;    
  20.         return;        
  21.     }
  22.    
  23.     else {    
  24.             for(c=0; c<number_of_chars; c++) {
  25.                 outputcout(x+chars_to_use[c], number_of_chars_left-1, separator);
  26.             }        
  27.     }
  28. }
  29.  
  30. void output(string x, int number_of_chars_left, string separator) {
  31.  
  32.     char c;
  33.        
  34.     if(number_of_chars_left==0) {
  35.         out << x << separator;    
  36.         return;        
  37.     }
  38.    
  39.     else {        
  40.             for(c=0; c<number_of_chars; c++) {
  41.                 output(x+chars_to_use[c], number_of_chars_left-1, separator);
  42.             }        
  43.     }
  44. }
  45.  
  46. void usage() {
  47.     cerr << "usage: wlg (-l|-w) (no_chars) (chars) [output file]" << endl;
  48.     exit(1);
  49. }
  50.  
  51.  
  52. int main(int argc, char *argv[]) {
  53.  
  54.     int how_many;
  55.     string separator;    
  56.        
  57.     if(argc<4)
  58.             usage();
  59.            
  60.     if(!strcmp(argv[1], "-l"))
  61.         separator="\n";
  62.     else if(!strcmp(argv[1], "-w"))
  63.         separator="\r\n";
  64.                
  65.     how_many=atoi(argv[2]);
  66.     strcpy(chars_to_use, argv[3]);
  67.     number_of_chars=strlen(chars_to_use);
  68.            
  69.     if(argc==4)                
  70.             outputcout("", how_many, separator);    
  71.    
  72.     if(argc==5) {    
  73.             out.open(argv[4]);            
  74.             output("", how_many, separator);
  75.             out.close();    
  76.     }
  77.            
  78.    
  79.    
  80. }
Advertisement
Add Comment
Please, Sign In to add comment