Markopy
Utilizing Markov Models for brute forcing attacks
Markov::Node< storageType > Class Template Reference

A node class that for the vertices of model. Connected with eachother using Edge. More...

#include <node.h>

Collaboration diagram for Markov::Node< storageType >:

Public Member Functions

 Node ()
 Default constructor. Creates an empty Node. More...
 
 Node (storageType _value)
 Constructor. Creates a Node with no edges and with given NodeValue. More...
 
Edge< storageType > * Link (Node< storageType > *)
 Link this node with another, with this node as its source. More...
 
Edge< storageType > * Link (Edge< storageType > *)
 Link this node with another, with this node as its source. More...
 
Node< storageType > * RandomNext (Markov::Random::RandomEngine *randomEngine)
 Chose a random node from the list of edges, with regards to its EdgeWeight, and TraverseNode to that. More...
 
bool UpdateEdges (Edge< storageType > *)
 Insert a new edge to the this.edges. More...
 
Edge< storageType > * FindEdge (storageType repr)
 Find an edge with its character representation. More...
 
Edge< storageType > * FindEdge (Node< storageType > *target)
 Find an edge with its pointer. Avoid unless neccessary because comptutational cost of find by character is cheaper (because of std::map) More...
 
unsigned char NodeValue ()
 Return character representation of this node. More...
 
void UpdateTotalVerticeWeight (long int offset)
 Change total weights with offset. More...
 
std::map< storageType, Edge< storageType > * > * Edges ()
 return edges More...
 
long int TotalEdgeWeights ()
 return total edge weights More...
 

Public Attributes

std::vector< Edge< storageType > * > edgesV
 

Private Attributes

storageType _value
 Character representation of this node. 0 for starter, 0xff for terminator. More...
 
long int total_edge_weights
 Total weights of the vertices, required by RandomNext. More...
 
std::map< storageType, Edge< storageType > * > edges
 A map of all edges connected to this node, where this node is at the LeftNode. Map is indexed by unsigned char, which is the character representation of the node. More...
 

Detailed Description

template<typename storageType>
class Markov::Node< storageType >

A node class that for the vertices of model. Connected with eachother using Edge.

This class will later be templated to accept other data types than char*.

Definition at line 24 of file node.h.

Constructor & Destructor Documentation

◆ Node() [1/2]

template<typename storageType >
Markov::Node< storageType >::Node

Default constructor. Creates an empty Node.

Definition at line 209 of file node.h.

209  {
210  this->_value = 0;
211  this->total_edge_weights = 0L;
212 };
storageType _value
Character representation of this node. 0 for starter, 0xff for terminator.
Definition: node.h:179
long int total_edge_weights
Total weights of the vertices, required by RandomNext.
Definition: node.h:184

◆ Node() [2/2]

template<typename storageType >
Markov::Node< storageType >::Node ( storageType  _value)

Constructor. Creates a Node with no edges and with given NodeValue.

Parameters
_value- Nodes character representation.

Example Use: Construct nodes

A node class that for the vertices of model. Connected with eachother using Edge.
Definition: node.h:24

Definition at line 203 of file node.h.

203  {
204  this->_value = _value;
205  this->total_edge_weights = 0L;
206 };

Member Function Documentation

◆ Edges()

template<typename storageType >
std::map< storageType, Markov::Edge< storageType > * > * Markov::Node< storageType >::Edges
inline

return edges

Definition at line 272 of file node.h.

272  {
273  return &(this->edges);
274 }
std::map< storageType, Edge< storageType > * > edges
A map of all edges connected to this node, where this node is at the LeftNode. Map is indexed by unsi...
Definition: node.h:190

Referenced by Markov::API::MarkovPasswords::Buff().

Here is the caller graph for this function:

◆ FindEdge() [1/2]

template<typename storageType >
Edge<storageType>* Markov::Node< storageType >::FindEdge ( Node< storageType > *  target)

Find an edge with its pointer. Avoid unless neccessary because comptutational cost of find by character is cheaper (because of std::map)

Parameters
target- target node.
Returns
Edge that is connected between this node, and the target node.

◆ FindEdge() [2/2]

template<typename storageType >
Markov::Edge< storageType > * Markov::Node< storageType >::FindEdge ( storageType  repr)

Find an edge with its character representation.

Parameters
repr- character NodeValue of the target node.
Returns
Edge that is connected between this node, and the target node.

Example Use: Construct and update edges

src->Link(target1);
src->Link(target2);
res = src->FindEdge('b');
Edge class used to link nodes in the model together.
Definition: edge.h:23
Edge< storageType > * Link(Node< storageType > *)
Link this node with another, with this node as its source.
Definition: node.h:220
Edge< storageType > * FindEdge(storageType repr)
Find an edge with its character representation.
Definition: node.h:260

Definition at line 260 of file node.h.

260  {
261  auto e = this->edges.find(repr);
262  if (e == this->edges.end()) return NULL;
263  return e->second;
264 };

◆ Link() [1/2]

template<typename storageType >
Markov::Edge< storageType > * Markov::Node< storageType >::Link ( Markov::Edge< storageType > *  v)

Link this node with another, with this node as its source.

DOES NOT create a new Edge.

Parameters
Edge- Edge that will accept this node as its LeftNode.
Returns
the same edge as parameter target.

Example Use: Construct and link nodes

Definition at line 227 of file node.h.

227  {
228  v->SetLeftEdge(this);
229  this->UpdateEdges(v);
230  return v;
231 }
void SetLeftEdge(Node< NodeStorageType > *)
Set LeftNode of this edge.
Definition: edge.h:150
bool UpdateEdges(Edge< storageType > *)
Insert a new edge to the this.edges.
Definition: node.h:252

◆ Link() [2/2]

template<typename storageType >
Markov::Edge< storageType > * Markov::Node< storageType >::Link ( Markov::Node< storageType > *  n)

Link this node with another, with this node as its source.

Creates a new Edge.

Parameters
target- Target node which will be the RightNode() of new edge.
Returns
A new node with LeftNode as this, and RightNode as parameter target.

Example Use: Construct nodes

Definition at line 220 of file node.h.

220  {
222  this->UpdateEdges(v);
223  return v;
224 }

◆ NodeValue()

template<typename storageType >
unsigned char Markov::Node< storageType >::NodeValue
inline

Return character representation of this node.

Returns
character representation at _value.

Definition at line 215 of file node.h.

215  {
216  return _value;
217 }

References Markov::Node< storageType >::_value.

Referenced by Markov::API::ModelMatrix::ConstructMatrix().

Here is the caller graph for this function:

◆ RandomNext()

template<typename storageType >
Markov::Node< storageType > * Markov::Node< storageType >::RandomNext ( Markov::Random::RandomEngine randomEngine)

Chose a random node from the list of edges, with regards to its EdgeWeight, and TraverseNode to that.

This operation is done by generating a random number in range of 0-this.total_edge_weights, and then iterating over the list of edges. At each step, EdgeWeight of the edge is subtracted from the random number, and once it is 0, next node is selected.

Returns
Node that was chosen at EdgeWeight biased random.

Example Use: Use randomNext to do a random walk on the model

char* buffer[64];
model.Import("model.mdl");
int len = 0;
Markov::Node<char>* temp_node;
while (true) {
temp_node = n->RandomNext(randomEngine);
if (len >= maxSetting) {
break;
}
else if ((temp_node == NULL) && (len < minSetting)) {
continue;
}
else if (temp_node == NULL){
break;
}
n = temp_node;
buffer[len++] = n->NodeValue();
}
bool Import(std::ifstream *)
Import a file to construct the model.
Definition: model.h:216
Node< NodeStorageType > * starterNode
Starter Node of this model.
Definition: model.h:198
Node< storageType > * RandomNext(Markov::Random::RandomEngine *randomEngine)
Chose a random node from the list of edges, with regards to its EdgeWeight, and TraverseNode to that.
Definition: node.h:234
unsigned char NodeValue()
Return character representation of this node.
Definition: node.h:215

Definition at line 234 of file node.h.

234  {
235 
236  //get a random NodeValue in range of total_vertice_weight
237  long int selection = randomEngine->random() % this->total_edge_weights;//distribution()(generator());// distribution(generator);
238  //make absolute, no negative modulus values wanted
239  //selection = (selection >= 0) ? selection : (selection + this->total_edge_weights);
240  for(int i=0;i<this->edgesV.size();i++){
241  selection -= this->edgesV[i]->EdgeWeight();
242  if (selection < 0) return this->edgesV[i]->TraverseNode();
243  }
244 
245  //if this assertion is reached, it means there is an implementation error above
246  std::cout << "This should never be reached (node failed to walk to next)\n"; //cant assert from child thread
247  assert(true && "This should never be reached (node failed to walk to next)");
248  return NULL;
249 }
std::vector< Edge< storageType > * > edgesV
Definition: node.h:173
virtual unsigned long random()=0

References Markov::Random::RandomEngine::random().

Here is the call graph for this function:

◆ TotalEdgeWeights()

template<typename storageType >
long int Markov::Node< storageType >::TotalEdgeWeights
inline

return total edge weights

Definition at line 277 of file node.h.

277  {
278  return this->total_edge_weights;
279 }

Referenced by Markov::API::ModelMatrix::ConstructMatrix().

Here is the caller graph for this function:

◆ UpdateEdges()

template<typename storageType >
bool Markov::Node< storageType >::UpdateEdges ( Markov::Edge< storageType > *  v)

Insert a new edge to the this.edges.

Parameters
edge- New edge that will be inserted.
Returns
true if insertion was successful, false if it fails.

Example Use: Construct and update edges

e1->AdjustEdge(25);
src->UpdateEdges(e1);
e2->AdjustEdge(30);
src->UpdateEdges(e2);
void AdjustEdge(long int offset)
Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
Definition: edge.h:137

Definition at line 252 of file node.h.

252  {
253  this->edges.insert({ v->RightNode()->NodeValue(), v });
254  this->edgesV.push_back(v);
255  //this->total_edge_weights += v->EdgeWeight();
256  return v->TraverseNode();
257 }
Node< NodeStorageType > * RightNode()
return edge's RightNode
Definition: edge.h:170
Node< NodeStorageType > * TraverseNode()
Traverse this edge to RightNode.
Definition: edge.h:143

◆ UpdateTotalVerticeWeight()

template<typename storageType >
void Markov::Node< storageType >::UpdateTotalVerticeWeight ( long int  offset)

Change total weights with offset.

Parameters
offsetto adjust the vertice weight with

Definition at line 267 of file node.h.

267  {
268  this->total_edge_weights += offset;
269 }

Member Data Documentation

◆ _value

template<typename storageType >
storageType Markov::Node< storageType >::_value
private

Character representation of this node. 0 for starter, 0xff for terminator.

Definition at line 179 of file node.h.

Referenced by Markov::Node< storageType >::NodeValue().

◆ edges

template<typename storageType >
std::map<storageType, Edge<storageType>*> Markov::Node< storageType >::edges
private

A map of all edges connected to this node, where this node is at the LeftNode. Map is indexed by unsigned char, which is the character representation of the node.

Definition at line 190 of file node.h.

◆ edgesV

template<typename storageType >
std::vector<Edge<storageType>*> Markov::Node< storageType >::edgesV

Definition at line 173 of file node.h.

◆ total_edge_weights

template<typename storageType >
long int Markov::Node< storageType >::total_edge_weights
private

Total weights of the vertices, required by RandomNext.

Definition at line 184 of file node.h.


The documentation for this class was generated from the following files: