Markopy
Utilizing Markov Models for brute forcing attacks
|
class for the final Markov Model, constructed from nodes and edges. More...
#include <model.h>
Public Member Functions | |
Model () | |
Initialize a model with only start and end nodes. More... | |
NodeStorageType * | RandomWalk (Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, NodeStorageType *buffer) |
Do a random walk on this model. More... | |
void | AdjustEdge (const NodeStorageType *payload, long int occurrence) |
Adjust the model with a single string. More... | |
bool | Import (std::ifstream *) |
Import a file to construct the model. More... | |
bool | Import (const char *filename) |
Open a file to import with filename, and call bool Model::Import with std::ifstream. More... | |
bool | Export (std::ofstream *) |
Export a file of the model. More... | |
bool | Export (const char *filename) |
Open a file to export with filename, and call bool Model::Export with std::ofstream. More... | |
Node< NodeStorageType > * | StarterNode () |
Return starter Node. More... | |
std::vector< Edge< NodeStorageType > * > * | Edges () |
Return a vector of all the edges in the model. More... | |
std::map< NodeStorageType, Node< NodeStorageType > * > * | Nodes () |
Return starter Node. More... | |
void | OptimizeEdgeOrder () |
Sort edges of all nodes in the model ordered by edge weights. More... | |
Private Attributes | |
std::map< NodeStorageType, Node< NodeStorageType > * > | nodes |
Map LeftNode is the Nodes NodeValue Map RightNode is the node pointer. More... | |
Node< NodeStorageType > * | starterNode |
Starter Node of this model. More... | |
std::vector< Edge< NodeStorageType > * > | edges |
A list of all edges in this model. More... | |
class for the final Markov Model, constructed from nodes and edges.
Each atomic piece of the generation result is stored in a node, while edges contain the relation weights. Extending: To extend the class, implement the template and inherit from it, as "class MyModel : public Markov::Model<char>". For a complete demonstration of how to extend the class, see MarkovPasswords.
Whole model can be defined as a list of the edges, as dangling nodes are pointless. This approach is used for the import/export operations. For more information on importing/exporting model, check out the github readme and wiki page.
Markov::Model< NodeStorageType >::Model |
Initialize a model with only start and end nodes.
Initialize an empty model with only a starterNode Starter node is a special kind of node that has constant 0x00 value, and will be used to initiate the generation execution from.
Definition at line 210 of file model.h.
void Markov::Model< NodeStorageType >::AdjustEdge | ( | const NodeStorageType * | payload, |
long int | occurrence | ||
) |
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.
Then, update the edge EdgeWeight from current node, to the terminator node.
This function is used for training purposes, as it can be used for adjusting the model with each line of the corpus file.
Example Use: Create an empty model and train it with string: "testdata"
string | - String that is passed from the training, and will be used to AdjustEdge the model with |
occurrence | - Occurrence of this string. |
Definition at line 337 of file model.h.
Referenced by Markov::API::MarkovPasswords::TrainThread().
|
inline |
Return a vector of all the edges in the model.
Definition at line 176 of file model.h.
bool Markov::Model< NodeStorageType >::Export | ( | const char * | filename | ) |
Open a file to export with filename, and call bool Model::Export with std::ofstream.
Example Use: Export file to filename
Definition at line 300 of file model.h.
Referenced by Markov::Markopy::CUDA::BOOST_PYTHON_MODULE(), Markov::Markopy::BOOST_PYTHON_MODULE(), and main().
bool Markov::Model< NodeStorageType >::Export | ( | std::ofstream * | f | ) |
Export a file of the model.
File contains a list of edges. Format is: Left_repr;EdgeWeight;right_repr. For more information on the format, check out the project wiki or github readme.
Iterate over this vertices, and their edges, and write them to file.
Example Use: Export file to ofstream
Definition at line 288 of file model.h.
Referenced by Markov::API::MarkovPasswords::Save().
bool Markov::Model< NodeStorageType >::Import | ( | const char * | filename | ) |
Open a file to import with filename, and call bool Model::Import with std::ifstream.
Example Use: Import a file with filename
Definition at line 280 of file model.h.
Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), Markov::API::ModelMatrix::Import(), and Markov::API::MarkovPasswords::MarkovPasswords().
bool Markov::Model< NodeStorageType >::Import | ( | std::ifstream * | f | ) |
Import a file to construct the model.
File contains a list of edges. For more info on the file format, check out the wiki and github readme pages. Format is: Left_repr;EdgeWeight;right_repr
Iterate over this list, and construct nodes and edges accordingly.
Example Use: Import a file from ifstream
Definition at line 216 of file model.h.
Referenced by Markov::API::MarkovPasswords::OpenDatasetFile().
|
inline |
Return starter Node.
Definition at line 181 of file model.h.
Referenced by Markov::API::MarkovPasswords::Buff(), and Markov::API::ModelMatrix::ConstructMatrix().
void Markov::Model< NodeStorageType >::OptimizeEdgeOrder |
Sort edges of all nodes in the model ordered by edge weights.
Definition at line 265 of file model.h.
Referenced by Markov::API::MarkovPasswords::Buff().
NodeStorageType * Markov::Model< NodeStorageType >::RandomWalk | ( | Markov::Random::RandomEngine * | randomEngine, |
int | minSetting, | ||
int | maxSetting, | ||
NodeStorageType * | buffer | ||
) |
Do a random walk on this model.
Start from the starter node, on each node, invoke RandomNext using the random engine on current node, until terminator node is reached. If terminator node is reached before minimum length criateria is reached, ignore the last selection and re-invoke randomNext
If maximum length criteria is reached but final node is not, cut off the generation and proceed to the final node. This function takes Markov::Random::RandomEngine as a parameter to generate pseudo random numbers from
This library is shipped with two random engines, Marsaglia and Mersenne. While mersenne output is higher in entropy, most use cases don't really need super high entropy output, so Markov::Random::Marsaglia is preferable for better performance.
This function WILL NOT reallocate buffer. Make sure no out of bound writes are happening via maximum length criteria.
Example Use: Generate 10 lines, with 5 to 10 characters, and print the output. Use Marsaglia
randomEngine | Random Engine to use for the random walks. For examples, see Markov::Random::Mersenne and Markov::Random::Marsaglia |
minSetting | Minimum number of characters to generate |
maxSetting | Maximum number of character to generate |
buffer | buffer to write the result to |
Definition at line 307 of file model.h.
Referenced by Markov::API::MarkovPasswords::GenerateThread().
|
inline |
Return starter Node.
Definition at line 171 of file model.h.
Referenced by Markov::API::ModelMatrix::ConstructMatrix().
|
private |
A list of all edges in this model.
Definition at line 204 of file model.h.
Referenced by Markov::Model< char >::Edges().
|
private |
Map LeftNode is the Nodes NodeValue Map RightNode is the node pointer.
Definition at line 193 of file model.h.
Referenced by Markov::Model< char >::Nodes().
|
private |
Starter Node of this model.
Definition at line 198 of file model.h.
Referenced by Markov::Model< char >::StarterNode().