Skip to content

Commit

Permalink
Merge pull request #56 from Omercanyt/dev
Browse files Browse the repository at this point in the history
Added minimum and maximum generation length limits
  • Loading branch information
ignis-sec authored May 19, 2021
2 parents 84abc6b + f34dd07 commit 686132a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Markopy/src/CLI/markopy_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
parser.add_argument("-d", "--dataset", help="Dataset file to read input from for training. Will be ignored for generation mode.")
parser.add_argument("-s", "--seperator",help="Seperator character to use with training data.(character between occurrence and value)")
parser.add_argument("-w", "--wordlist", help="Wordlist file path to export generation results to. Will be ignored for training mode")
parser.add_argument("--min", default=6, help="Minimum length that is allowed during generation")
parser.add_argument("--max", default=12,help="Maximum length that is allowed during generation")
parser.add_argument("-n", "--count", help="Number of lines to generate. Ignored in training mode.")
parser.add_argument("-v", "--verbosity",action="count", help="Output verbosity.")
args = parser.parse_args()
Expand Down Expand Up @@ -89,7 +91,7 @@ def cli_generate(model):
if(os.path.isfile(args.wordlist)):
logging.pprint(f"{args.wordlist} exists and will be overwritten.", 1)

model.Generate(int(args.count), args.wordlist)
model.Generate(int(args.count), args.wordlist, args.min, args.max)



Expand Down
24 changes: 19 additions & 5 deletions MarkovModel/src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,30 @@ bool Markov::Model<NodeStorageType>::Export(const char* filename) {
}

template <typename NodeStorageType>
NodeStorageType* Markov::Model<NodeStorageType>::RandomWalk() {
NodeStorageType* Markov::Model<NodeStorageType>::RandomWalk(int minSetting, int maxSetting) {
Markov::Node<NodeStorageType>* n = this->starterNode;
int len = 0;
NodeStorageType *ret = new NodeStorageType[64];

Markov::Node<NodeStorageType> *temp_node;
while (n != NULL) {
n = n->RandomNext();
//n = n->RandomNext();
temp_node = n->RandomNext();
//dirty cutoff, needs better solution
if (len == 60) break;
if (n == NULL) break;
if (len == 60)
break;
if (len > maxSetting) {
//std::cout<<"MAX ->"<< "node*: " << temp_node << ", len: " << len << "\n";
break;
}

if ((temp_node == NULL) && (len < minSetting)) {
//std::cout << "node*: " << temp_node << ", len: " << len << "\n";
continue;
}

if (temp_node == NULL)
break;
n = temp_node;

//std::cout << n->NodeValue();
ret[len++] = n->NodeValue();
Expand Down
2 changes: 1 addition & 1 deletion MarkovModel/src/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Markov {
* Start from the starter node, invoke RandomNext on current node until terminator node is reached.
* @return Null terminated string that was generated.
*/
NodeStorageType* RandomWalk();
NodeStorageType* RandomWalk(int minSetting, int maxSetting);

/** @brief Adjust the model with a single string.
* Start from the starter node, and for each character, AdjustEdge the edge EdgeWeight from current node to the next, until NULL character is reached.
Expand Down
4 changes: 2 additions & 2 deletions MarkovPasswords/src/markovPasswords.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ std::ofstream* MarkovPasswords::Save(const char* filename) {
}


void MarkovPasswords::Generate(unsigned long int n, const char* wordlistFileName) {
void MarkovPasswords::Generate(unsigned long int n, const char* wordlistFileName, int minLen, int maxLen) {
char* res;
char print[100];
std::ofstream wordlist;


wordlist.open(wordlistFileName);
for (int i = 0; i < n; i++) {
res = this->RandomWalk();
res = this->RandomWalk(minLen, maxLen);
#ifdef _WIN32
strcpy_s(print, 100, (char*)res);
#else
Expand Down
2 changes: 1 addition & 1 deletion MarkovPasswords/src/markovPasswords.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MarkovPasswords : public Markov::Model<char>{
* @param n - Number of passwords to generate.
* @return std::ofstream* of the output file.
*/
void Generate(unsigned long int n, const char* wordlistFileName);
void Generate(unsigned long int n, const char* wordlistFileName, int minLen=6, int maxLen=12);

private:
std::ifstream* datasetFile;
Expand Down

0 comments on commit 686132a

Please sign in to comment.