1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#include <iostream>
#include <string>
#include <array>
#include <cmath>
#include <time.h>
#include <iomanip>
using namespace std;
int main(){
char* passArray = NULL;
int charArray[] = {0, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122};
int number, numRemain, findRemain, length, timeLeft;
char thisChar;
time_t start = 0,end;
string passCheck = "";
string passWord = "9f2Al";
cout << "Enter the maximum length of the password: ";
cin >> length;
passArray = new char[length];
double timeDifference;
double percentDone = 0, percentDoneLast = 0, percentDoneDiff = 0;
double availChars = 63;
double possible = pow(availChars,length);
double updateSpeed = 10-(length/2);
int updateRate = possible/pow(updateSpeed,length);
for(number = 0; number < possible; number ++){
percentDone = 100*number/possible;
percentDoneDiff = percentDone - percentDoneLast;
for(int i = 0; i < length; i++){
if(i==0){
findRemain = pow(availChars,(length-(i+1)));
numRemain = number % findRemain;
thisChar = char(charArray[number/findRemain]);
passArray[i] = thisChar;
}else if(i==(length-1)){
findRemain = pow(availChars,(length-(i)));
numRemain = number % findRemain;
thisChar = char(charArray[numRemain]);
passArray[i] = thisChar;
}else{
numRemain = numRemain % findRemain;
findRemain = pow(availChars,(length-(i+1)));
thisChar = char(charArray[numRemain/findRemain]);
passArray[i] = thisChar;
}
}
for(int f=0; f < length; f++){
if(passArray[f] != NULL){
passCheck += passArray[f];
}
}
if(passCheck == passWord){
cout << passCheck << " -- This is the password. "<< endl;
system("pause");
break;
}else{
passCheck.clear();
}
if(number%updateRate==0){
time(&end);
timeDifference = difftime (end,start);
timeLeft = timeDifference*((100-percentDone)/percentDoneDiff);
if(timeLeft >0){
cout << setprecision(5) << percentDone << "%" << " Time Remaining: " << timeLeft << '\r';
}else{
cout << setprecision(5) << percentDone << "%" << '\r';
}
percentDoneLast = percentDone;
time(&start);
}
}
cout<< endl;
system("pause");
return 0;
}
|