From: couturie <couturie@extinction> Date: Thu, 28 Sep 2017 08:08:07 +0000 (+0200) Subject: new X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/commitdiff_plain/7611dec2f1fe770d473b8d18dedbbdd1db41c187?hp=11c01e55387d9439baa811b6e956a7ca7d6e409d new --- diff --git a/IDA/test_mat2.cpp b/IDA/test_mat2.cpp index 20ccca7..474c572 100644 --- a/IDA/test_mat2.cpp +++ b/IDA/test_mat2.cpp @@ -9,8 +9,6 @@ #include <iostream> #include <fstream> #include <vector> - - #include <iostream> // std::cout, std::fixed #include <iomanip> #include <math.h> @@ -79,7 +77,7 @@ void rc4keyperm(byte *key,int len, int rp,byte *sc, int size_DK) { Mat<byte> readFullFile(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); + ifstream stream("lena_small2.png", ios::in | ios::binary | ios::ate); sizeFile=stream.tellg(); cout<<sizeFile<<endl; stream.seekg(0, ios::beg); @@ -108,7 +106,7 @@ Mat<byte> readFullFile(int n, int k, int& sizeFile, int &lc) { Mat<byte> 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); + ifstream stream("lena_small2.png", ios::in | ios::binary | ios::ate); sizeFile=stream.tellg(); cout<<sizeFile<<endl; stream.seekg(0, ios::beg); @@ -148,9 +146,9 @@ void buildFullRankIDA(Cube<byte>& IDAmat, Cube<short> &invIDAmat, int q, int n, Cube<byte> rm1(RM1,1,1,q*n*n/4); rm1.reshape(n/2,n/2,q); - cout<<"rm1"<<endl; + /* cout<<"rm1"<<endl; cout<<rm1<<endl; - + */ @@ -178,15 +176,15 @@ void buildFullRankIDA(Cube<byte>& IDAmat, Cube<short> &invIDAmat, int q, int n, sub2.submat(n/2,0,n-1,n/2-1)=-rm2+eye<Mat<short>>(n/2,n/2); sub2.submat(n/2,n/2,n-1,n-1)=rm2; - cout<<"det"<<endl; + /*cout<<"det"<<endl; mat toto=conv_to<mat>::from(sub2); cout<<det(toto)<<endl; - + */ invIDAmat.slice(i)=sub2; } - cout<<IDAmat<<endl; - cout<<invIDAmat<<endl; + //cout<<IDAmat<<endl; + //cout<<invIDAmat<<endl; } void buildPartialRankIDA(Cube<byte>& IDAmat, int q, int n, int k, byte* DK) { @@ -222,7 +220,7 @@ void buildPartialRankIDA(Cube<byte>& IDAmat, int q, int n, int k, byte* DK) { } */ - cout<<IDAmat<<endl; + // cout<<IDAmat<<endl; } @@ -235,7 +233,7 @@ int main( int argc, char *argv[] ) { int full=0; int q=2; - int n=4; + int n=8; int k=4; int Tb=64; int l=10;//399*Tb; @@ -285,8 +283,8 @@ int main( int argc, char *argv[] ) { else M=readPartialFile(n,k,sizeFile,lc); - // cout<<"M "<<endl; - // cout<<M<<endl; + cout<<"M "<<endl; + cout<<M<<endl; arma_rng::set_seed(time(NULL)); @@ -295,7 +293,8 @@ int main( int argc, char *argv[] ) { Cube<byte> IDAmat; Cube<short> invIDAmat; - + + if(full) { IDAmat.resize(n,n,q); @@ -327,28 +326,46 @@ int main( int argc, char *argv[] ) { Mat<byte> C; Mat<char> D2; - C=IDAmat.slice(0)*M; + //full +// C=IDAmat.slice(0)*M; + +//partial + C=IDAmat.slice(0).submat(0,0,n-1,k-1)*M; + M.save("M.bin",raw_binary); if(full) { - //Mat<short> D=invIDAmat.slice(0)*C; + Mat<short> D=invIDAmat.slice(0)*C; - mat A=conv_to<mat>::from(IDAmat.slice(0).submat(0,0,n-1,n-1)); + /*mat A=conv_to<mat>::from(IDAmat.slice(0).submat(0,0,n-1,n-1)); mat B=conv_to<mat>::from(C.submat(0,0,n-1,lc-1)); mat D=solve(A,B); - cout<<D<<endl; + */ D2=conv_to<Mat<char>>::from(D); + cout<<D2<<endl; } else { - mat A=conv_to<mat>::from(IDAmat.slice(0).submat(0,0,n-1,k-1)); - mat B=conv_to<mat>::from(C.submat(0,0,n-1,lc-1)); + + IDAmat.resize(k,k,q); + invIDAmat.resize(k,k,q); + buildFullRankIDA(IDAmat, invIDAmat, q, k, &DK[0]); + + + mat A=conv_to<mat>::from(IDAmat.slice(0).submat(0,0,k-1,k-1)); + + mat B=conv_to<mat>::from(C.submat(0,0,k-1,lc-1)); mat D=solve(A,B); +// mat D=inv(A)*B; - cout<<D<<endl; - D2=conv_to<Mat<char>>::from(D); +// cout<<D<<endl; + +// Mat<short> D=invIDAmat.slice(0)*C.submat(0,0,k-1,lc-1); + + D2=conv_to<Mat<char>>::from(D); + cout<<D2<<endl; }