Commit d2ef140d authored by Clément Février's avatar Clément Février

Small optimizations

parent 59ec03e0
......@@ -75,11 +75,11 @@ unsigned char * hashSHA1(const std::string & input)
return output;
}*/
void findPassword(const unsigned char * hash, const std::string * list, const unsigned int & COUNT, const unsigned int & L, const unsigned int N_THREAD)
void findPassword(const unsigned char * hash, const std::string * list, const unsigned short int & COUNT, const unsigned char & L, const unsigned char N_THREAD)
{
// Create a group of threads
boost::thread_group t;
for(unsigned int i = 0; i < COUNT; ++i)
for(unsigned short int i = 0; i < COUNT; ++i)
{
// Launch a thread
// Initiate the recursive function with the first letter
......@@ -97,7 +97,7 @@ void findPassword(const unsigned char * hash, const std::string * list, const un
t.join_all();
}
void findPasswordThread(const unsigned char * hash, const std::string & pass, const std::string * list, const unsigned int & COUNT, const unsigned int & L, const unsigned int & l, const unsigned int N_THREAD)
void findPasswordThread(const unsigned char * hash, const std::string & pass, const std::string * list, const unsigned short int & COUNT, const unsigned char & L, const unsigned char & l, const unsigned char N_THREAD)
{
// If the password to test is build,
// test if it is the correct one
......@@ -108,7 +108,7 @@ void findPasswordThread(const unsigned char * hash, const std::string & pass, co
// Test if hashes match
// Assume that the correct password expected if shown otherwise
bool found = true;
for(size_t i = 0; i < 20; ++i)
for(unsigned char i = 0; i < 20; ++i)
{
// This condition is strictly equivalent to
// if(sha1[i] ^ hash[i])
......@@ -137,7 +137,8 @@ void findPasswordThread(const unsigned char * hash, const std::string & pass, co
{
// Display once again the hash.
std::cout<<"* Hash SHA1:"<<std::endl;
for (int x = 0; x < 20; x++) {
for (unsigned char x = 0; x < 20; ++x)
{
std::printf("%x ", hash[x]); //Hex-format
}
std::cout<<std::endl;
......@@ -151,7 +152,7 @@ void findPasswordThread(const unsigned char * hash, const std::string & pass, co
{
// If the password is not build yet,
// keep appending characters.
for(unsigned int i = 0; i < COUNT; ++i)
for(unsigned short int i = 0; i < COUNT; ++i)
{
// pass + list[i]
// adds a new letter to the password to test.
......
......@@ -52,7 +52,7 @@ unsigned char * hashSHA1(const std::string & input);
* COUNT: Length of list.
* L: Maximum length of the password to test.
* N_THREAD: Number of threads to launch. */
void findPassword(const unsigned char * hash, const std::string * list, const unsigned int & COUNT, const unsigned int & L, const unsigned int N_THREAD);
void findPassword(const unsigned char * hash, const std::string * list, const unsigned short int & COUNT, const unsigned char & L, const unsigned char N_THREAD);
/* Seek for password, display the latter if found it
and exit the program.
......@@ -64,4 +64,4 @@ void findPassword(const unsigned char * hash, const std::string * list, const un
* L: Maximum length of the password to test.
* l: Current length of the password to test.
* N_THREAD: Number of threads to launch. */
void findPasswordThread(const unsigned char * hash, const std::string & pass, const std::string * list, const unsigned int & COUNT, const unsigned int & L, const unsigned int & l, const unsigned int N_THREAD);
void findPasswordThread(const unsigned char * hash, const std::string & pass, const std::string * list, const unsigned short int & COUNT, const unsigned char & L, const unsigned char & l, const unsigned char N_THREAD);
......@@ -70,9 +70,9 @@
int main ()
{
// Number of threads to launch.
const unsigned int N_THREAD = 64;
const unsigned char N_THREAD = 64;
// Max length of password.
const unsigned int MaxLength = 4;
const unsigned char MaxLength = 4;
// SHA-1 hash to crack.
// Below few examples and their corresponding password.
// ZZZ
......@@ -86,7 +86,7 @@ int main ()
//std::string HASH = "18 f3 f 1b a4 c6 2e 2b 46 e 69 33 6 b3 9a d e2 7d 74 7c";
//std::string HASH = "18 f3 f 1b a4 c6 2e 2b 46 e 69 33 6 b3 9a d e2 7d 74 7c";
// If set, ignore HASH and compute test's SHA-1 hash and attempt to crack it.
const std::string test = "";
const std::string test = "fo";
// Pointer used to store the SHA-1 hash.
unsigned char * hash;
// std::vector used to create hash.
......@@ -114,7 +114,7 @@ int main ()
{
// Add space every 2 characters starting from the end.
std::string space = " ";
for(size_t i = 19; i > 0; --i)
for(unsigned char i = 19; i > 0; --i)
{
HASH.insert(2 * i, space);
}
......@@ -132,7 +132,7 @@ int main ()
}
// Display the input SHA-1 hash.
std::cout<<"* Hash SHA1:"<<std::endl;
for (int x = 0; x < 20; x++)
for (int x = 0; x < 20; ++x)
{
std::printf("%x ", hash[x]); //Hex-format
}
......@@ -142,7 +142,7 @@ int main ()
// count: Increment used to access list element in the loop.
// Also used to pass the length of the list
// to findPassword.
unsigned int count = 0;
unsigned short int count = 0;
// First item is "".
// Used to build password to test smaller than MaxLength.
list[0] = "";
......@@ -152,7 +152,7 @@ int main ()
// In this case, all from 33 to 126 included.
// The reverted order is used to test in priority
// lowercase-based passwords.
for(unsigned int i = 126; i > 32; --i)
for(unsigned short int i = 126; i > 32; --i)
{
// Convert the dec value of i to char.
list[count] = (char)i;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment