X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/blobdiff_plain/b10cad1b1a4f87f61815936361592e99bffa1b2a..e276f56dbd21fca9b743bc6c8b28ead5516c9cc9:/IDA/test_mat2.cpp?ds=sidebyside diff --git a/IDA/test_mat2.cpp b/IDA/test_mat2.cpp index e61ecac..474c572 100644 --- a/IDA/test_mat2.cpp +++ b/IDA/test_mat2.cpp @@ -9,8 +9,6 @@ #include #include #include - - #include // std::cout, std::fixed #include #include @@ -76,10 +74,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("lena_small2.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("lena_small2.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) { @@ -117,9 +146,9 @@ void buildFullRankIDA(Cube& IDAmat, Cube &invIDAmat, int q, int n, Cube rm1(RM1,1,1,q*n*n/4); rm1.reshape(n/2,n/2,q); - cout<<"rm1"<& IDAmat, Cube &invIDAmat, int q, int n, sub2.submat(n/2,0,n-1,n/2-1)=-rm2+eye>(n/2,n/2); sub2.submat(n/2,n/2,n-1,n-1)=rm2; - cout<<"det"<::from(sub2); cout<& IDAmat, int q, int n, int k, byte* DK) { + + byte Sbox[256]; + byte RM1[q*n*k]; + + + rc4key(DK, Sbox, 8); + prga(Sbox, q*n*k, RM1); + Cube rm1(RM1,1,1,q*n*k); + rm1.reshape(n,k,q); + IDAmat=rm1; +/* + cout<<"rm1"< sub(n,k); + sub.submat(0,0,n-1,k-1)=rm1.slice(i); + + + IDAmat.slice(i)=sub; + + + cout<<"det "<::from(sub); + cout< IDAmat(n,n,q); - Cube invIDAmat(n,n,q); - buildFullRankIDA(IDAmat, invIDAmat, q, n, &DK[0]); - - // rc4key(&DK[8], sc, 16); - - + int lc; + int sizeFile; + Mat M; + if(full) + M=readFullFile(n,k,sizeFile,lc); + else + M=readPartialFile(n,k,sizeFile,lc); + cout<<"M "< IDAmat; + Cube invIDAmat; + + + 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"); @@ -237,20 +323,54 @@ int main( int argc, char *argv[] ) { cout< C; + Mat D2; + //full +// C=IDAmat.slice(0)*M; + +//partial + C=IDAmat.slice(0).submat(0,0,n-1,k-1)*M; - Mat C=IDAmat.slice(0)*M; M.save("M.bin",raw_binary); -// Mat D=invIDAmat.slice(0)*C; + + if(full) { + Mat D=invIDAmat.slice(0)*C; + + + /*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); + */ + + + D2=conv_to>::from(D); + cout<::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,k-1,k-1)); + + mat B=conv_to::from(C.submat(0,0,k-1,lc-1)); + mat D=solve(A,B); +// mat D=inv(A)*B; + +// cout< D=invIDAmat.slice(0)*C.submat(0,0,k-1,lc-1); + + D2=conv_to>::from(D); + cout< D2=conv_to>::from(D); + // cout<<"D2"<