X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/blobdiff_plain/b10cad1b1a4f87f61815936361592e99bffa1b2a..11c01e55387d9439baa811b6e956a7ca7d6e409d:/IDA/test_mat2.cpp?ds=inline diff --git a/IDA/test_mat2.cpp b/IDA/test_mat2.cpp index e61ecac..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,10 +189,51 @@ void buildFullRankIDA(Cube& IDAmat, Cube &invIDAmat, int q, int n, 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 +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"<