00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef _LengthAttack_H_
00010 #define _LengthAttack_H_
00011
00012 #include "Word.h"
00013 #include <vector>
00014 using namespace std;
00015
00016 enum findKey_LengthBasedResult {
00017 FAILED ,
00018 TIME_EXPIRED ,
00019 SUCCESSFULL
00020 };
00021
00022 #define AL1 1
00023 #define AL2 2
00024 #define AL3 3
00025
00026 typedef pair< int , vector< Word > > ELT;
00027
00028
00029
00030
00032 class LengthAttackBase
00033 {
00034 public:
00036 virtual int type()=0;
00037
00039
00048 virtual findKey_LengthBasedResult findKey_LengthBased( int N ,
00049 const vector< Word >& A1 ,
00050 const vector< Word >& A2 ,
00051 const vector< Word >& B ,
00052 int sec = 9999999, ostream& out = cout )=0;
00053
00054 };
00055
00056
00057
00058
00059
00061
00066 class LengthAttack_A1 : public LengthAttackBase
00067 {
00068 public:
00069 LengthAttack_A1(){}
00070 int type() { return AL1; }
00072
00081 findKey_LengthBasedResult findKey_LengthBased( int N ,
00082 const vector< Word >& A1 ,
00083 const vector< Word >& A2 ,
00084 const vector< Word >& B ,
00085 int sec = 9999999, ostream& out = cout );
00086 private:
00087 int sbgpGeneratorsWeight( const vector< Word >& A );
00088 void addNewElt( const vector< Word >& A , set< ELT >& checkedElements , set< ELT >& uncheckedElements );
00089 void tryElt( int N , const ELT& cur , const vector< Word >& B , set< ELT >& checkedElements , set< ELT >& uncheckedElements );
00090 bool check_ifVectorsEqual( int N , const vector< Word >& A1 , const vector< Word >& A2 );
00091 };
00092
00093
00094
00095
00097
00103 class LengthAttack_A2 : public LengthAttackBase
00104 {
00105 public:
00106 LengthAttack_A2(){}
00107 int type() { return AL2; }
00109
00118 findKey_LengthBasedResult findKey_LengthBased( int N ,
00119 const vector< Word >& A1 ,
00120 const vector< Word >& A2 ,
00121 const vector< Word >& B ,
00122 int sec = 9999999, ostream& out = cout );
00123 private:
00124 int sbgpGeneratorsWeight( const vector< Word >& A );
00125 void addNewElt( const vector< Word >& A , set< ELT >& checkedElements , set< ELT >& uncheckedElements );
00126 void tryElt( int N , const ELT& cur , const vector< Word >& B , set< ELT >& checkedElements , set< ELT >& uncheckedElements );
00127 void tryElt( int N , const ELT& cur , const vector< Word >& B , set< ELT >& checkedElements , set< ELT >& uncheckedElements, ostream& out );
00128 bool check_ifVectorsEqual( int N , const vector< Word >& A1 , const vector< Word >& A2 );
00129 };
00130
00131
00132
00133
00135
00143 class LengthAttack_A3 : public LengthAttackBase
00144 {
00145 public:
00146 LengthAttack_A3(){}
00147 int type() { return AL3; }
00149
00158 findKey_LengthBasedResult findKey_LengthBased( int N ,
00159 const vector< Word >& A1 ,
00160 const vector< Word >& A2 ,
00161 const vector< Word >& B ,
00162 int sec = 9999999, ostream& out = cout );
00163 private:
00164 void addProducts( const vector<Word>& elem_set, vector<Word>& ext_set, vector<Word>& ext_set_sg_gens, const Word& sel_gen, int sel_gen_sg );
00165 void addAllProducts( const vector<Word>& elem_set, vector<Word>& ext_set, vector<Word>& ext_set_sg_gens );
00166 int sbgpGeneratorsWeight( const vector< Word >& A );
00167 void addNewElt( const vector< Word >& A , set< ELT >& checkedElements , set< ELT >& uncheckedElements );
00168 void tryElt( int N , const ELT& cur , const vector< Word >& B , set< ELT >& checkedElements , set< ELT >& uncheckedElements );
00169 void tryElt( int N , const ELT& cur , const vector< Word >& B , const vector<Word>& B_sg_gens,set< ELT >& checkedElements ,
00170 set< ELT >& uncheckedElements,
00171 bool is_B_extended,
00172 ostream& out );
00173
00174 bool check_ifVectorsEqual( int N , const vector< Word >& A1 , const vector< Word >& A2 );
00175 };
00176
00177 #endif