Brute-force attack algorithm
May 22, 2013 at 5:43pm UTC
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?
May 22, 2013 at 6:12pm UTC
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 May 22, 2013 at 6:13pm UTC
Topic archived. No new replies allowed.