Solution:
Using brute force we can crack a password by attempting multiple probablities
like for example if actual password CABD, we attempt possibilities ACDB, ADBC, BACD, BCDA, BDAC, CABD, CBDA, CDAB, DABC, DBCA, DCBA
#include <iostream>
#include <string>
using namespace std;
//we are using brute force attack
string Brute_Force(string actual_password){
int ascii_NUM=256; //number of possible ascii characters
for (int c1=0; c1<ascii_NUM; c1++) {
for (int c2=0; c2<ascii_NUM; c2++) {
for (int c3=0; c3<ascii_NUM; c3++) {
for (int c4=0; c4<ascii_NUM; c4++) {
// convert each digit into char and concat into string
string passwd_attempt = string()+(char)c1+(char)c2+(char)c3+(char)c4;
//check if attempted password is equals to the original password
if (passwd_attempt==actual_password) return passwd_attempt;
}
}
}
}
//if password not found
throw "not found";
}
Thank you, have a great day:-)
Get Answers For Free
Most questions answered within 1 hours.