#include <iostream.h>
#include <stdlib.h>
#include <string>
#include <stdio.h> // fopen (), fflush ()
#include <conio.h> // getche ()
#include <ctype.h> // toupper ()
#include <time.h> // clock ()
namespace
{
int IndexCaracs;
char *TabCaracs;
string Nom;
bool Trouve = false;
const char *StrToChar (string Str)
{
char *Tab = (char *) malloc ((Str.length ()+1) * sizeof (char));
for (int i = 0; i < Str.length (); ++i) Tab [i] = Str [i];
Tab [Str.length ()] = '\0';
return Tab;
}
const char *Build (string Name, string Pass)
{
// unrar e -av- -c- -cu -p<mdp> -y <nom du rar>
string Command = "unrar e -av- -c- -cu -inul -p" + Pass + " -y " + Name;
return StrToChar (Command);
}
bool CheckYesNo (string Question)
{
char c;
for ( ; toupper (c) != 'O' && toupper (c) != 'N'; cout << '\n')
{
cout << Question << " [o/n] ? ";
c = getche ();
}
return (toupper (c) == 'O');
}
void SearchRec (string MdPInit, int NbRest)
{
if (Trouve) return;
if (!NbRest)
{
cout << "Test de : " << MdPInit << endl;
if (0 == system (Build (Nom, MdPInit)))
{
cout << " => OK ! " << endl;
Trouve = true;
}
return;
}
for (int i = 0; i < IndexCaracs; ++i)
SearchRec (MdPInit + TabCaracs [i], NbRest-1);
}
void Chrono (clock_t d, clock_t f)
{
int NbH, NbM, NbS;
NbS = (int) ((double) (f-d)/CLOCKS_PER_SEC);
NbH = (NbS - (NbS % 3600)) / 3600;
NbS -= NbH * 3600;
NbM = (NbS - (NbS % 60)) / 60;
NbS -= NbM * 60;
cout << "Crackage effectue en "
<< NbH << 'h' << NbM << 'm' << NbS << 's' << endl;
}
}
int main()
{
int NbCar, Temp;
char c;
string MotDePasse;
bool Majus, Minus, Number, Other;
FILE *fd;
clock_t Debut, Fin;
Majus = Minus = Number = Other = false;
NbCar = 0;
cout << " Extraction d'un fichier Winrar " << endl
<< " ------------------------------ " << endl << endl;
if (! (fd = fopen ("UnRAR.exe", "r")))
{
cerr << "/!\\ Pour que le programme fonctionne vous devez placer cet executable dans le" << endl
<< " repertoire de WinRAR" << endl << endl;
system ("PAUSE");
return -1;
}
fclose (fd);
cout << "Entrez le nom de votre archive (sans le \".rar\") : "; getline (cin, Nom); Nom += ".rar";
if (!(fd = fopen (StrToChar (Nom), "r")))
{
cerr << "/!\\ Pour que le programme fonctionne vous devez placer votre archive dans le" << endl
<< " repertoire de WinRAR" << endl << endl;
system ("PAUSE");
return -1;
}
fclose (fd);
while ((!Majus) && (!Minus) && (!Number) && (!Other))
{
Majus = CheckYesNo ("Tester les majuscules");
Minus = CheckYesNo ("Tester les minuscules");
Number = CheckYesNo ("Tester les chiffres");
Other = CheckYesNo ("Tester les autres caracteres imprimables");
if ((!Majus) && (!Minus) && (!Number) && (!Other))
cerr << "/!\\ Vous devez au moins examiner 1 type de caracteres" << endl;
}
while ((NbCar < 1) || (NbCar > 8))
{
cout << "Nombre max. de caracteres du mot de passe [<= 8] ? ";
NbCar = getche () - 48;
if ((NbCar < 1) || (NbCar > 8)) cerr << " /!\\ Nombre incorrect !" << endl;
}
cout << endl << endl;
fflush (stdin);
cout << "Archive : " << '"' << Nom << '"' << endl;
if (Majus) cout << "Tester les majuscules" << endl;
if (Minus) cout << "Tester les minuscules" << endl;
if (Number) cout << "Tester les chiffres" << endl;
if (Other) cout << "Tester les autres caracteres" << endl;
cout << "Mot de passe de " << NbCar << " caracteres maximum" << endl << endl;
system ("PAUSE");
// Début de la recherche du mot de passe...
IndexCaracs = 0; Temp = 0;
if (Majus) IndexCaracs += 26;
if (Minus) IndexCaracs += 26;
if (Number) IndexCaracs += 10;
if (Other) IndexCaracs += 27;
TabCaracs = (char *) malloc (IndexCaracs * sizeof (char));
if (Minus) for (int i = 0; i < 26; ++i) TabCaracs [Temp++] = char (97+i);
if (Majus) for (int i = 0; i < 26; ++i) TabCaracs [Temp++] = char (65+i);
if (Number) for (int i = 0; i < 10; ++i) TabCaracs [Temp++] = char (48+i);
if (Other)
for (int i = 33; i < 127; ++i)
{
if (i == 48) i = 58;
else if (i == 65) i = 91;
else if (i == 97) i = 123;
else if ((i == 34) || (i == 38) || (i == 45) || (i == 62) || (i == 94))
continue;
TabCaracs [Temp++] = char (i);
}
Debut = clock ();
for (int i = 1; i <= NbCar; ++i) SearchRec ("", i);
Fin = clock ();
cout << endl;
Chrono (Debut, Fin);
system ("PAUSE");
return 0;
}