From: couturie Date: Thu, 26 Apr 2018 17:08:26 +0000 (+0200) Subject: first version of IDA (many files are missing) X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/commitdiff_plain/a503f71d90ef2d1946c0088e01513805092f3cce?ds=inline;hp=66236412e0919d9c0d257e519a84228766473045 first version of IDA (many files are missing) --- diff --git a/IDA/ida.cpp b/IDA/ida.cpp new file mode 100644 index 0000000..9a1d31b --- /dev/null +++ b/IDA/ida.cpp @@ -0,0 +1,381 @@ +// g++ -std=c++11 -O4 -msse2 -msse3 -msse4 -fopenmp -O3 test_mat2.cpp -o test_mat2 -I /home/couturie/tools/armadillo-6.200.5/include/ -lc -lm -lpthread -lgfortran -DMAX_STACK_ALLOC=2048 -Wall -m64 -DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DNO_WARMUP -DMAX_CPU_NUMBER=8 -DNO_AFFINITY -UCOMPLEX -DDOUBLE -I/home/couturie/tools/openblas/include -I/home/couturie/Downloads/OpenBLAS-0.2.15/ /home/couturie/tools/openblas/lib/libopenblas_haswellp-r0.2.15.a + + + +#include +#include +#include + +#include +#include // std::ostream_iterator +#include +#include +#include // std::cout, std::fixed +#include +#include + +using namespace arma; +using namespace std; +int key_size=256; + + + const int mm=251; + +typedef unsigned char byte; + + +template +T mod(T a, int n) +{ + return a - floor(a/n)*n; +} + +inline int positive_modulo(int i, int n) { + return (i % n + n) % n; +} + +void Bezout(int rkm2,int rkm1,int *res,int ukm1=0,int vkm1=1,int ukm2=1,int vkm2=0){ +/*r(k-4)=r(k-3)*q(k-2)+r(k-2) <=> r(k-2)=a*u(k-2)+b*v(k-2) + + +r(k-3)=r(k-2)*q(k-1)+r(k-1) <=> r(k-1)=a*u(k-1)+b*v(k-1) + +r(k-2)=r(k-1)*q(k)+r(k) <=> r(k)=a*u(k)+b*v(k) avec u(k)=u(k-2)-qk*u(k-1) et v(k)=v(k-2)-qk*v(k-1)*/ + + int rk=rkm2%rkm1; + int qk=(rkm2-rk)/rkm1; + if(rk==0) { + cout< data, const char *fileName,long size_file=0) { + byte* vec=(byte*)data.memptr(); +// cout<<"vec "< v =conv_to< vector >::from(data); + ofstream outfile(fileName, ios::out | ofstream::binary); + + copy(v.begin(), v.end(), ostream_iterator(outfile)); + outfile.close(); +*/ + +} + +Row readFile( const char *fileName) { + /*ifstream stream(fileName, ios::in | ios::binary | ios::ate); + int sizeFile=stream.tellg(); + stream.seekg(0, ios::beg); + vector vec((istreambuf_iterator(stream)), istreambuf_iterator()); + Row d2(vec); + */ + + + FILE* pFile = fopen (fileName, "rb"); + fseek(pFile, 0L, SEEK_END); + int sz = ftell(pFile); + rewind(pFile); + byte* vec=new byte[sz]; + fread (vec , sizeof(byte), sz, pFile); + fclose (pFile); + + + Row d2(vec,sz); + delete vec; + + + cout<<"vec ici"< +convert_vec256_to_vec250(vector vec256){ + + + int num_val_greater = std::count_if(vec256.begin(), vec256.end(), [](int i){return i>=mm;}); + vector vec250; + vec250.reserve(vec256.size()+num_val_greater); + // cout<<"ICI "<=mm-1) { + vec250.push_back(mm-1); + vec250.push_back(vec256[i]-mm+1); + //vec250[l++]=(mm-1); + + //vec250[l++]=vec256[i]-mm+1; + } + else { + vec250.push_back(vec256[i]); + //vec250[l++]=vec256[i]; + } + } + //cout<<"ICI "< +convert_vec250_to_vec256(vector vec250){ + + + vector vec256; + vec256.reserve(vec250.size()); + + for (int i=0; i readFullFile(int n, int k, long& sizeFile, int &lc) { + +// ifstream stream("lena.png", ios::in | ios::binary | ios::ate); + ifstream stream("/home/couturie/Downloads/CARCARIASS.zip", ios::in | ios::binary | ios::ate); +// ifstream stream("lena_small2.png", ios::in | ios::binary | ios::ate); + sizeFile=stream.tellg(); + cout<>=8; + } + + cout<<"rebuild"<=0;i--) { + res<<=8; + res+=mysize[i]; + } + + cout<<(long)res< contents((istreambuf_iterator(stream)), istreambuf_iterator()); + cout<<"res contents "< contents2=convert_vec256_to_vec250(contents); + cout<<"res contents2 "< contents3=convert_vec250_to_vec256(contents2); + + /*cout<<"LAST"< matData(&contents2[0],1,contents2.size()); + + +/* Row test(&contents[0],contents.size()); + cout<<"test "< S; + S=readFullFile(n,k,sizeFile,lc); + + + + arma_rng::set_seed(time(NULL)); + //S=randi>(k,100000000); + + cout<<"S "< G= randi>(n,k); + cout<<"G "< C=conv_to>::from(G)*conv_to>::from(S); + C=mod(C,mm); + cout<<"C "< C2=conv_to>::from(C); + + + //write files + for(int i=0;i C3; + + //read k files among n + for(int i=0;i d2=readFile(str.c_str()); + C3.insert_rows(i,d2); + } + + + + + +// Mat Cs=C.rows(0,k-1); + Mat Cs=conv_to>::from(C3); + + cout< Gs2=conv_to>::from(G).rows(0,k-1); + mat Gs=conv_to::from(Gs2); + + cout<<"tot"< S2=conv_to>::from(SS2); + S2=mod(S2,mm); +// cout< res =conv_to< vector >::from(S2.row(0)); + cout<<"res size "< res2=convert_vec250_to_vec256(res); + cout<<"res2 size "<=0;i--) { + size_file<<=8; + size_file+=mysize[i]; + } + + cout<<"size file "<<(long)size_file<