Brute-force attack algorithm

So basically I want to test all combinations of characters in fixed size string passing them into Hashing function and testing the result with the target hash. Is there any algorithm for that?
Main idea:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
bool next(std::string& x)
{
    size_t len = x.size();
    bool overflow = true;
    while(overflow) {
        overflow = false;
        if(--len == 0) 
            return false;
        (x[len] == 'z')?(overflow = true, x[len] = 'a'):x[len] += 1;
    }
    return true;
}

std::pair<bool, std::string> brute5()
{
    std::string brute('a', 5);
    do
        if (hash(brute) == desired_hash)
           return std::make_pair(true, brute);
    while(next(brute));
    return std::make_pair(false, std::string());
}
Last edited on
Topic archived. No new replies allowed.