I want to generate a list of passwords of a cretain length passwords from a packet FILE. The packet file means a .txt FILE which contains more than 1M passwords of certain lengths. I want to store password of DIFFERENT length in a various .txt FILES

/*this code is used to generate a packet for dictionary attacks which conatins the passwords of certain length */ 
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
#define MAX 50
void FileString(char *,int);
void createFile(ofstream &,ifstream &,char *,char *,int);
int main() {
    ofstream outputfile;
    ifstream intputfile;
    int len1,len2;
    char filename[MAX],p_file[MAX];

    cout<<"Enter your packet file : "; cin>>p_file;
    cout<<"Enter your range to obtained passwords for dictionary attacks...."<<endl<<endl;

    cout<<"Enter length-1 : "; cin>>len1;
    cout<<"Enter length-2 : "; cin>>len2;

    cout<<"Total "<<len2-len1<<" files will generated "<<endl;

    return 0;
void FileString(char *FILE,int f)
    char name[MAX] = {"-length-pass.txt"};
    char temp[MAX];

    strcpy(FILE,temp); //it created the .txt file strings
void createFile(ofstream &outfile,ifstream &infile,char *FILE,char *packet,int f)
    char data[MAX];

    } else {
        cout<<"Data is failed to written in a File "<<endl;


This a function it takes data and show nothing FILES to me

Recommended Answers

All 2 Replies

Your method is inefficient. Suppose len1 equals 5 and len2 equals 15. I have an input file containing a million words and my goal is to create 10 files ("5-length-pass.txt", "6-length-pass.txt", ..., "14-length-pass.txt"). You are trying to read the in the entire input file 10 times. That's inefficient. How about, instead, creating an array of 10 ofstreams from the start? Read the file once. As each input word is read once, check the length and output it to the correct ofstream, like so.

while(infile >> data)
    int len = strlen(data);
    if(len < len1 || len >= len2)
        continue; // length not within the range
    // outfile is an array of ofstream
    outfile[len - len1] << data << "\n";

As for why nothing is happening, I believe you have less-than and greater-than mixed up in line 22. len2 is greater than len1, so that loop starting on line 22 will never execute.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.