X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/blobdiff_plain/70b995d30a4c75869c4223dbb931802246f52d94..11c01e55387d9439baa811b6e956a7ca7d6e409d:/IDA/test_mat2.cpp?ds=sidebyside diff --git a/IDA/test_mat2.cpp b/IDA/test_mat2.cpp index e09acbd..20ccca7 100644 --- a/IDA/test_mat2.cpp +++ b/IDA/test_mat2.cpp @@ -76,10 +76,10 @@ void rc4keyperm(byte *key,int len, int rp,byte *sc, int size_DK) { } -Mat readFile(int n, int k, int& sizeFile, int &lc) { +Mat readFullFile(int n, int k, int& sizeFile, int &lc) { - ifstream stream("/home/couturie/ajeter/lena.png", ios::in | ios::binary | ios::ate); -// ifstream stream("/home/couturie/ajeter/lena_small.png", ios::in | ios::binary | ios::ate); +// ifstream stream("lena.png", ios::in | ios::binary | ios::ate); + ifstream stream("/home/couturie/ajeter/lena_small.png", ios::in | ios::binary | ios::ate); sizeFile=stream.tellg(); cout< readFile(int n, int k, int& sizeFile, int &lc) { } +Mat readPartialFile(int n, int k, int& sizeFile, int &lc) { + +// ifstream stream("lena.png", ios::in | ios::binary | ios::ate); + ifstream stream("/home/couturie/ajeter/lena_small.png", ios::in | ios::binary | ios::ate); + sizeFile=stream.tellg(); + cout< contents2(k*lc,0); + vector contents((istreambuf_iterator(stream)), istreambuf_iterator()); + copy ( contents.begin(), contents.end(), contents2.begin() ); + + + + + Mat matData(&contents2[0],1,contents2.size()); + + cout << "file size: " << contents2.size() << endl; + + matData.reshape(k,lc); + cout<& IDAmat, Cube &invIDAmat, int q, int n, byte* DK) { @@ -158,7 +189,7 @@ void buildFullRankIDA(Cube& IDAmat, Cube &invIDAmat, int q, int n, cout<& IDAmat, int q, int n, int k, byte* DK) { +void buildPartialRankIDA(Cube& IDAmat, int q, int n, int k, byte* DK) { byte Sbox[256]; byte RM1[q*n*k]; @@ -168,7 +199,8 @@ void buildKRankIDA(Cube& IDAmat, int q, int n, int k, byte* DK) { prga(Sbox, q*n*k, RM1); Cube rm1(RM1,1,1,q*n*k); rm1.reshape(n,k,q); - + IDAmat=rm1; +/* cout<<"rm1"<& IDAmat, int q, int n, int k, byte* DK) { IDAmat.slice(i)=sub; + cout<<"det "<::from(sub); + cout<& IDAmat, int q, int n, int k, byte* DK) { int main( int argc, char *argv[] ) { + + int full=0; + int q=2; int n=4; int k=4; @@ -235,31 +275,41 @@ int main( int argc, char *argv[] ) { -/* -// Initialization of IDA and inverse IDA matrix - Cube IDAmat(n,n,q); - Cube invIDAmat(n,n,q); - buildFullRankIDA(IDAmat, invIDAmat, q, n, &DK[0]); -*/ + int lc; + int sizeFile; + Mat M; + if(full) + M=readFullFile(n,k,sizeFile,lc); + else + M=readPartialFile(n,k,sizeFile,lc); + + // cout<<"M "< IDAmat(n,k,q); - buildKRankIDA(Cube& IDAmat, q, n, k, &DK[0]); + arma_rng::set_seed(time(NULL)); - // rc4key(&DK[8], sc, 16); - - +// Initialization of IDA and inverse IDA matrix + Cube IDAmat; + Cube invIDAmat; - - - arma_rng::set_seed(time(NULL)); + if(full) + { + IDAmat.resize(n,n,q); + invIDAmat.resize(n,n,q); + buildFullRankIDA(IDAmat, invIDAmat, q, n, &DK[0]); + } + else { + IDAmat.resize(n,k,q); + buildPartialRankIDA(IDAmat, q, n, k, &DK[0]); + } + + - int lc; - int sizeFile; - Mat M=readFile(n,k,sizeFile,lc); // Ma data; // data.load("/home/couturie/ajeter/lena.png"); @@ -274,20 +324,36 @@ int main( int argc, char *argv[] ) { cout< C=IDAmat.slice(0)*M; - M.save("M.bin",raw_binary); -// Mat D=invIDAmat.slice(0)*C; + Mat C; + Mat D2; + C=IDAmat.slice(0)*M; + M.save("M.bin",raw_binary); + + if(full) { + //Mat D=invIDAmat.slice(0)*C; - mat A=conv_to::from(IDAmat.slice(0).submat(0,0,k-1,n-1)); - mat B=conv_to::from(C.submat(0,0,k-1,lc-1)); + + mat A=conv_to::from(IDAmat.slice(0).submat(0,0,n-1,n-1)); + mat B=conv_to::from(C.submat(0,0,n-1,lc-1)); + mat D=solve(A,B); + cout<>::from(D); + } + else { + mat A=conv_to::from(IDAmat.slice(0).submat(0,0,n-1,k-1)); + mat B=conv_to::from(C.submat(0,0,n-1,lc-1)); + mat D=solve(A,B); + + cout<>::from(D); + } - Mat D2=conv_to>::from(D); + // cout<<"D2"<