// maak een edge aan de hand van de data uit de filereader. int Circuit::CreateEdges(std::vector<std::string> Edges) { pView->Print("Create edges and link them!"); try { for (int i = 0; i < Edges.size(); i++) { // maak de edge Edge *pEdge = (Edge *)Factory::instance()->RequestComponent(_EDGE); // zet in lijst. if (pEdge != nullptr) this->Edges.push_back(pEdge); else throw 1; // link de edge if (!Link(Edges.at(i), pEdge)) throw 2; } } catch (int e) { // file heeft fouten? if (e == 1) return ErrorFound("Error in creating edges!"); else if (e == 2) return ErrorFound("Error in linking components & edges!"); } return 1; }
// maak probes int Circuit::CreateProbes(std::vector<std::string> Probes) { pView->Print("Create probes!"); try { for (int i = 0; i < Probes.size(); i++) { // maak een probe Probe *pProbe = (Probe *)Factory::instance()->RequestComponent(_PROBE); if (pProbe != nullptr) { // zet de probe id. pProbe->SetId(Probes.at(i).substr(0, Probes.at(i).find(":"))); this->Probes.push_back(pProbe); } else throw 1; } } catch (int e) { // probe error return ErrorFound("Error in creating probes!"); } return 1; }
int main( int argc, char *argv[] ) { InitKey(); //PLAYING //byte_t attack[28] = { 'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a', // 'a','a','d','m','i','n','a','t','r','u','e','\0' }; char attack[1] = {'\0'}; size_t mida; byte_t *eData = CreateInfoString( attack, &mida ); printf("mida:%lu\n",mida); printf("dimCorr:%d\n",!(mida%16)); byte_t *temp = malloc(mida); int i; for( i = 0; i < 16; i++ ) { temp[i] = eData[i]; } for( i = 1; i < ( mida/16 - 1 ) ; i++ ) { int j; for( j = 0; j < 16; j++ ) { temp[16*i+j] = 0; } } for( i = 0; i < 16; i++ ) { temp[ i + (mida-16) ] = eData[i]; } int err = ErrorFound( temp, mida ); printf("Error found:%d\n",err); byte_t ivf[16]; for( i = 0; i < 16; i++ ) ivf[i] = temp[i]^temp[ i + (mida-16) ]; if( !memcmp( IV, ivf, 16 ) ) { printf("IV was the key\n"); for( i = 0; i < 16; i++ ) printf("%02X",ivf[i]); printf("\n"); } else { printf("IV was not the key or smth else has gone wrong\n"); } return 0; }
// maak inputs int Circuit::CreateInputs(std::vector<std::string> Inputs) { if (!this->_inputsSet) { // vraag voor de input waardes this->_high = pView->AskForInputHigh(); this->_low = pView->AskForInputLow(); this->_inputsSet = true; } pView->Print("Create inputs!"); try { for (int i = 0; i < Inputs.size(); i++) { // maak input Input *pInput = (Input *)Factory::instance()->RequestComponent(_INPUT); // zet de input waardes if (Inputs.at(i).find("INPUT_HIGH") != std::string::npos) { pInput->InsertValue(this->_high); } else if (Inputs.at(i).find("INPUT_LOW") != std::string::npos) { pInput->InsertValue(this->_low); } else throw 1; // error if (pInput != nullptr) { // zet id pInput->SetId(Inputs.at(i).substr(0, Inputs.at(i).find(":"))); this->Inputs.push_back(pInput); } else throw 1; } } catch (int e) { // input kon niet gemaakt worden return ErrorFound("Error in creating inputs!"); } return 1; }
// maakt nodes aan uit de filereader. int Circuit::CreateNodes(std::vector<std::string> Nodes) { pView->Print("Create nodes!"); try { for (int i = 0; i < Nodes.size(); i++) { std::string Line = Nodes.at(i); Node *pNode = nullptr; std::map<std::string, uint> nodeTypes = { {"AND", _AND}, {"NAND", _NAND}, {"NOR", _NOR}, {"NOT", _NOT}, {"OR", _OR}, {"XNOR", _XNOR}, {"XOR", _XOR} }; // maak desbetreffende node aan. for (auto const& nodeType : nodeTypes) { if (Line.find(nodeType.first) != std::string::npos) pNode = (Node *)Factory::instance()->RequestComponent(nodeType.second); } // node is niet gemaakt geef error if (pNode == nullptr) throw 1; // zet id pNode->SetId(Nodes.at(i).substr(0, Nodes.at(i).find(":"))); this->Nodes.push_back(pNode); } } catch (int e) { // nodes konden niet gemaakt worden return ErrorFound("Error in creating nodes!"); } return 1; }