Loading include/statsgen.h +27 −23 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include <iostream> #include <regex> #include <queue> #include <thread> #define MAX_THREADS 32 Loading Loading @@ -126,65 +127,78 @@ public: * @brief useful to hide statistics below 1% * @param hr: 1 to hide, else 0 */ void setHiderare(int hr); inline void setHiderare(const int& hr) { hiderare = hr; } /** * @brief Defining the number of best results the user wants to see, * and so the result should be clearer * @param t: number of interesting results */ void setTop(int t); inline void setTop(const int& t) { top = t; } /** * @brief Defining a regular expression to analyse only * some interesting passwords * @param reg: regular expression */ void setRegex(const std::string& reg); inline void setRegex(const std::string& reg) { current_regex = reg; use_regex = true; } /** * @brief Useful to know if the database uses the format withcount * @param var: true if database uses the format withcount, else false */ void setWithcount(bool var); inline void setWithcount(const bool& wc) { withcount = wc; } /** * @brief Filter for the size of the simple masks, can be * used as an optimisation option * @param limit: number that limit the size of the simple masks */ void setLimitSimplemask(int limit); inline void setLimitSimplemask(const int& limit) { limitSimplemask = limit; } /** * @brief Filter for the size of the advanced masks, can be * used as an optimisation option * @param limit: number that limit the size of the advanced masks */ void setLimitAdvancedmask(int limit); inline void setLimitAdvancedmask(const int& limit) { limitAdvancedmask = limit; } /** * @brief Number of threads the user wants to use * @param nb: number of usable threads */ void setNbThread(int nb); inline void setNbThread(const int& nb) { int max = std::thread::hardware_concurrency(); if (nb > max) { nbThread = max; } else { nbThread = nb; } } /** * @brief Defining all security rules */ void setSecurityRules(); void setSecurityRules(int length,int special,int digit,int upper,int lower); void askSecurityRules(); void setSecurityRules(const int& length, const int& special, const int& digit, const int& upper, const int& lower); /** * @brief Where to write masks * @param outfile: the file where to write masks */ void setOutfile(const std::string& outfile); inline void setOutfile(const std::string& outfile) { outfile_name = outfile; } /** * @brief enable debugging */ void enableDebug(); inline void enableDebug() { debug_enabled = true; } void message(const char* messages...); /** * @brief print the warning message Loading Loading @@ -216,9 +230,6 @@ public: inline const IntOccurrence& getStatsLength() const { return stats_length; } inline const StringOccurrence& getStatsCharsets() const { return stats_charactersets; } private: std::string filename; Loading Loading @@ -276,14 +287,7 @@ private: * @param sizeAdvancedMask: size of the current advanced mask * @param sizeSimpleMask: size of the current simple mask */ void analyse_letter(const char & letter, char & last_simplemask, std::string & simplemask_string, std::string & advancedmask_string, Policy & policy, int & sizeAdvancedMask, int & sizeSimpleMask); /** * @brief Analyse the characterset of the current password * @param charset: characterset of the current password * @param policy: current number of digit, lower, upper and special for the current password */ void analyse_charset(std::string & charset, const Policy & policy); // void analyse_letter(const char & letter, char & last_simplemask, std::string & simplemask_string, std::string & advancedmask_string, Policy & policy, int & sizeAdvancedMask, int & sizeSimpleMask); /** * @brief Analyse a password Loading @@ -293,7 +297,7 @@ void analyse_charset(std::string & charset, const Policy & policy); * @param limitAdvancedmask: define the limit for the size of advanced masks * @param limitSimplemask: define the limit for the size of simple masks */ Container analyze_password(const std::string & password, SecurityRules & sr, const int & limitAdvancedmask, const int & limitSimplemask); // Container analyze_password(const std::string & password, SecurityRules & sr, const int & limitAdvancedmask, const int & limitSimplemask); /** * @brief Update minima and maxima of all general data from analysed passwords Loading src/cli/main.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -105,7 +105,7 @@ int main(int argc,char* argv[]) { case 'p': statsgen.setNbThread(atoi(optarg)); break; case 's': statsgen.setSecurityRules(); break; statsgen.askSecurityRules(); break; default: showHelp(); break; } Loading src/core/statsgen.cpp +28 −85 Original line number Diff line number Diff line Loading @@ -35,58 +35,9 @@ Statsgen::Statsgen(const std::string& name) { } } void Statsgen::setHiderare(int val) { hiderare = val; } void Statsgen::setTop(int val) { top = val; } void Statsgen::setRegex(const string& expr) { current_regex = string(expr); use_regex = true; } void Statsgen::setWithcount(bool val) { withcount = val; } void Statsgen::setLimitSimplemask(int val) { limitSimplemask = val; } void Statsgen::setLimitAdvancedmask(int val) { limitAdvancedmask = val; } void Statsgen::setNbThread(int nb) { int max = thread::hardware_concurrency(); if (nb > max) { nbThread = max; } else { nbThread = nb; } } void Statsgen::setOutfile(const string& outfile){ outfile_name = outfile; } void Statsgen::enableDebug(){ debug_enabled = true; } void Statsgen::warn(const char* messages...){ void Statsgen::message(const char* messages...){ va_list args; va_start(args, messages); cerr << "[Warning]"; while (*messages != '\0'){ cerr << " "; if (*messages == 'd') { Loading @@ -97,31 +48,23 @@ void Statsgen::warn(const char* messages...){ } messages++; } cerr << endl; va_end(args); } void Statsgen::warn(const char* messages...){ cerr << "[Warning]"; message(messages); cerr << endl; } void Statsgen::debug(const char* messages...){ if (!debug_enabled) return; va_list args; va_start(args, messages); cerr << "[Debug]"; while (*messages != '\0'){ cerr << " "; if (*messages == 'd') { cerr << va_arg(args, int); } else{ cerr << va_arg(args, char*); } messages++; } message(messages); cerr << endl; va_end(args); } void Statsgen::setSecurityRules() { void Statsgen::askSecurityRules() { wcout << "\nMinimal length of a password:" << endl; cin >> minLength; Loading @@ -138,7 +81,7 @@ void Statsgen::setSecurityRules() { cin >> minUpper; } void Statsgen::setSecurityRules(int length,int special,int digit,int upper,int lower) { void Statsgen::setSecurityRules(const int& length, const int& special, const int& digit, const int& upper, const int& lower) { minLength = length; minSpecial = special; minDigit = digit; Loading Loading @@ -403,7 +346,7 @@ void analyse_letter(const char & letter, char & last_simplemask, string & simple } string analyse_charset(const Policy & policy) { const string analyse_charset(const Policy & policy) { string charset; if (policy.digit && !policy.lower && !policy.upper && !policy.special) { charset = "numeric"; Loading Loading @@ -493,33 +436,33 @@ Container analyze_password(const string & password, SecurityRules & sr, const in void updateMinMax(minMax & minMaxValue, const Policy & pol) { if (minMaxValue.mindigit == -1 || minMaxValue.mindigit > pol.digit) { minMaxValue.mindigit = pol.digit; void updateMinMax(minMax & m, const Policy & pol) { if (m.mindigit == -1 || m.mindigit > pol.digit) { m.mindigit = pol.digit; } if (minMaxValue.maxdigit == -1 || minMaxValue.maxdigit < pol.digit) { minMaxValue.maxdigit = pol.digit; if (m.maxdigit == -1 || m.maxdigit < pol.digit) { m.maxdigit = pol.digit; } if (minMaxValue.minlower == -1 || minMaxValue.minlower > pol.lower) { minMaxValue.minlower = pol.lower; if (m.minlower == -1 || m.minlower > pol.lower) { m.minlower = pol.lower; } if (minMaxValue.maxlower == -1 || minMaxValue.maxlower < pol.lower) { minMaxValue.maxlower = pol.lower; if (m.maxlower == -1 || m.maxlower < pol.lower) { m.maxlower = pol.lower; } if (minMaxValue.minupper == -1 || minMaxValue.minupper > pol.upper) { minMaxValue.minupper = pol.upper; if (m.minupper == -1 || m.minupper > pol.upper) { m.minupper = pol.upper; } if (minMaxValue.maxupper == -1 || minMaxValue.maxupper < pol.upper) { minMaxValue.maxupper = pol.upper; if (m.maxupper == -1 || m.maxupper < pol.upper) { m.maxupper = pol.upper; } if (minMaxValue.minspecial == -1 || minMaxValue.minspecial > pol.special) { minMaxValue.minspecial = pol.special; if (m.minspecial == -1 || m.minspecial > pol.special) { m.minspecial = pol.special; } if (minMaxValue.maxspecial == -1 || minMaxValue.maxspecial < pol.special) { minMaxValue.maxspecial = pol.special; if (m.maxspecial == -1 || m.maxspecial < pol.special) { m.maxspecial = pol.special; } } Loading Loading
include/statsgen.h +27 −23 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include <iostream> #include <regex> #include <queue> #include <thread> #define MAX_THREADS 32 Loading Loading @@ -126,65 +127,78 @@ public: * @brief useful to hide statistics below 1% * @param hr: 1 to hide, else 0 */ void setHiderare(int hr); inline void setHiderare(const int& hr) { hiderare = hr; } /** * @brief Defining the number of best results the user wants to see, * and so the result should be clearer * @param t: number of interesting results */ void setTop(int t); inline void setTop(const int& t) { top = t; } /** * @brief Defining a regular expression to analyse only * some interesting passwords * @param reg: regular expression */ void setRegex(const std::string& reg); inline void setRegex(const std::string& reg) { current_regex = reg; use_regex = true; } /** * @brief Useful to know if the database uses the format withcount * @param var: true if database uses the format withcount, else false */ void setWithcount(bool var); inline void setWithcount(const bool& wc) { withcount = wc; } /** * @brief Filter for the size of the simple masks, can be * used as an optimisation option * @param limit: number that limit the size of the simple masks */ void setLimitSimplemask(int limit); inline void setLimitSimplemask(const int& limit) { limitSimplemask = limit; } /** * @brief Filter for the size of the advanced masks, can be * used as an optimisation option * @param limit: number that limit the size of the advanced masks */ void setLimitAdvancedmask(int limit); inline void setLimitAdvancedmask(const int& limit) { limitAdvancedmask = limit; } /** * @brief Number of threads the user wants to use * @param nb: number of usable threads */ void setNbThread(int nb); inline void setNbThread(const int& nb) { int max = std::thread::hardware_concurrency(); if (nb > max) { nbThread = max; } else { nbThread = nb; } } /** * @brief Defining all security rules */ void setSecurityRules(); void setSecurityRules(int length,int special,int digit,int upper,int lower); void askSecurityRules(); void setSecurityRules(const int& length, const int& special, const int& digit, const int& upper, const int& lower); /** * @brief Where to write masks * @param outfile: the file where to write masks */ void setOutfile(const std::string& outfile); inline void setOutfile(const std::string& outfile) { outfile_name = outfile; } /** * @brief enable debugging */ void enableDebug(); inline void enableDebug() { debug_enabled = true; } void message(const char* messages...); /** * @brief print the warning message Loading Loading @@ -216,9 +230,6 @@ public: inline const IntOccurrence& getStatsLength() const { return stats_length; } inline const StringOccurrence& getStatsCharsets() const { return stats_charactersets; } private: std::string filename; Loading Loading @@ -276,14 +287,7 @@ private: * @param sizeAdvancedMask: size of the current advanced mask * @param sizeSimpleMask: size of the current simple mask */ void analyse_letter(const char & letter, char & last_simplemask, std::string & simplemask_string, std::string & advancedmask_string, Policy & policy, int & sizeAdvancedMask, int & sizeSimpleMask); /** * @brief Analyse the characterset of the current password * @param charset: characterset of the current password * @param policy: current number of digit, lower, upper and special for the current password */ void analyse_charset(std::string & charset, const Policy & policy); // void analyse_letter(const char & letter, char & last_simplemask, std::string & simplemask_string, std::string & advancedmask_string, Policy & policy, int & sizeAdvancedMask, int & sizeSimpleMask); /** * @brief Analyse a password Loading @@ -293,7 +297,7 @@ void analyse_charset(std::string & charset, const Policy & policy); * @param limitAdvancedmask: define the limit for the size of advanced masks * @param limitSimplemask: define the limit for the size of simple masks */ Container analyze_password(const std::string & password, SecurityRules & sr, const int & limitAdvancedmask, const int & limitSimplemask); // Container analyze_password(const std::string & password, SecurityRules & sr, const int & limitAdvancedmask, const int & limitSimplemask); /** * @brief Update minima and maxima of all general data from analysed passwords Loading
src/cli/main.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -105,7 +105,7 @@ int main(int argc,char* argv[]) { case 'p': statsgen.setNbThread(atoi(optarg)); break; case 's': statsgen.setSecurityRules(); break; statsgen.askSecurityRules(); break; default: showHelp(); break; } Loading
src/core/statsgen.cpp +28 −85 Original line number Diff line number Diff line Loading @@ -35,58 +35,9 @@ Statsgen::Statsgen(const std::string& name) { } } void Statsgen::setHiderare(int val) { hiderare = val; } void Statsgen::setTop(int val) { top = val; } void Statsgen::setRegex(const string& expr) { current_regex = string(expr); use_regex = true; } void Statsgen::setWithcount(bool val) { withcount = val; } void Statsgen::setLimitSimplemask(int val) { limitSimplemask = val; } void Statsgen::setLimitAdvancedmask(int val) { limitAdvancedmask = val; } void Statsgen::setNbThread(int nb) { int max = thread::hardware_concurrency(); if (nb > max) { nbThread = max; } else { nbThread = nb; } } void Statsgen::setOutfile(const string& outfile){ outfile_name = outfile; } void Statsgen::enableDebug(){ debug_enabled = true; } void Statsgen::warn(const char* messages...){ void Statsgen::message(const char* messages...){ va_list args; va_start(args, messages); cerr << "[Warning]"; while (*messages != '\0'){ cerr << " "; if (*messages == 'd') { Loading @@ -97,31 +48,23 @@ void Statsgen::warn(const char* messages...){ } messages++; } cerr << endl; va_end(args); } void Statsgen::warn(const char* messages...){ cerr << "[Warning]"; message(messages); cerr << endl; } void Statsgen::debug(const char* messages...){ if (!debug_enabled) return; va_list args; va_start(args, messages); cerr << "[Debug]"; while (*messages != '\0'){ cerr << " "; if (*messages == 'd') { cerr << va_arg(args, int); } else{ cerr << va_arg(args, char*); } messages++; } message(messages); cerr << endl; va_end(args); } void Statsgen::setSecurityRules() { void Statsgen::askSecurityRules() { wcout << "\nMinimal length of a password:" << endl; cin >> minLength; Loading @@ -138,7 +81,7 @@ void Statsgen::setSecurityRules() { cin >> minUpper; } void Statsgen::setSecurityRules(int length,int special,int digit,int upper,int lower) { void Statsgen::setSecurityRules(const int& length, const int& special, const int& digit, const int& upper, const int& lower) { minLength = length; minSpecial = special; minDigit = digit; Loading Loading @@ -403,7 +346,7 @@ void analyse_letter(const char & letter, char & last_simplemask, string & simple } string analyse_charset(const Policy & policy) { const string analyse_charset(const Policy & policy) { string charset; if (policy.digit && !policy.lower && !policy.upper && !policy.special) { charset = "numeric"; Loading Loading @@ -493,33 +436,33 @@ Container analyze_password(const string & password, SecurityRules & sr, const in void updateMinMax(minMax & minMaxValue, const Policy & pol) { if (minMaxValue.mindigit == -1 || minMaxValue.mindigit > pol.digit) { minMaxValue.mindigit = pol.digit; void updateMinMax(minMax & m, const Policy & pol) { if (m.mindigit == -1 || m.mindigit > pol.digit) { m.mindigit = pol.digit; } if (minMaxValue.maxdigit == -1 || minMaxValue.maxdigit < pol.digit) { minMaxValue.maxdigit = pol.digit; if (m.maxdigit == -1 || m.maxdigit < pol.digit) { m.maxdigit = pol.digit; } if (minMaxValue.minlower == -1 || minMaxValue.minlower > pol.lower) { minMaxValue.minlower = pol.lower; if (m.minlower == -1 || m.minlower > pol.lower) { m.minlower = pol.lower; } if (minMaxValue.maxlower == -1 || minMaxValue.maxlower < pol.lower) { minMaxValue.maxlower = pol.lower; if (m.maxlower == -1 || m.maxlower < pol.lower) { m.maxlower = pol.lower; } if (minMaxValue.minupper == -1 || minMaxValue.minupper > pol.upper) { minMaxValue.minupper = pol.upper; if (m.minupper == -1 || m.minupper > pol.upper) { m.minupper = pol.upper; } if (minMaxValue.maxupper == -1 || minMaxValue.maxupper < pol.upper) { minMaxValue.maxupper = pol.upper; if (m.maxupper == -1 || m.maxupper < pol.upper) { m.maxupper = pol.upper; } if (minMaxValue.minspecial == -1 || minMaxValue.minspecial > pol.special) { minMaxValue.minspecial = pol.special; if (m.minspecial == -1 || m.minspecial > pol.special) { m.minspecial = pol.special; } if (minMaxValue.maxspecial == -1 || minMaxValue.maxspecial < pol.special) { minMaxValue.maxspecial = pol.special; if (m.maxspecial == -1 || m.maxspecial < pol.special) { m.maxspecial = pol.special; } } Loading