From: couturie Date: Sun, 27 May 2018 18:50:59 +0000 (+0200) Subject: ida X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/commitdiff_plain/26cfeb68c1da44bc454806933dde5459455e113b ida --- diff --git a/IDA/Makefile b/IDA/Makefile index 8d7d811..71745c6 100644 --- a/IDA/Makefile +++ b/IDA/Makefile @@ -15,5 +15,8 @@ ida: ida.cpp ida_gf64: ida_gf64.cpp g++ -o $@ $< -std=c++11 -O3 -lm -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mavx -g -O3 -Wall -I/home/couturie/ajeter/jerasure/include /home/couturie/ajeter/jerasure/src/.libs/jerasure.o /home/couturie/ajeter/jerasure/src/.libs/galois.o -lgf_complete -fpermissive +ida_gf65: ida_gf65.cpp + g++ -o $@ $< -std=c++11 -O3 -lm -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mavx -g -O3 -Wall -I/home/couturie/ajeter/jerasure/include /home/couturie/ajeter/jerasure/src/.libs/jerasure.o /home/couturie/ajeter/jerasure/src/.libs/galois.o -lgf_complete -fpermissive + clean: rm test_mat2 ida ida_gf64 diff --git a/IDA/ida_gf65.cpp b/IDA/ida_gf65.cpp new file mode 100644 index 0000000..09c4162 --- /dev/null +++ b/IDA/ida_gf65.cpp @@ -0,0 +1,565 @@ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include // std::random_shuffle +#include // std::vector +extern "C" { + #include "jerasure.h" +} + +typedef unsigned long mylong; +#define LLUI (long long unsigned int) + + +using namespace std; + +string cloud[5]={"dropboxida1","googleida1","megaida1","onedriveida1","pcloudida1"}; + + +void display(mylong *mat, int r, int c) { + for(int i=0;imultiply.w64(gf,m1[i*c1+k], m2[k*c2+j]); + } + } + } + return product; +} + + + +int invert_matrix(gf_t *gf, mylong *mat, mylong *inv, int rows) +{ + int cols, i, j, k, x, rs2; + int row_start; + mylong tmp, inverse; + + cols = rows; + + k = 0; + for (i = 0; i < rows; i++) { + for (j = 0; j < cols; j++) { + inv[k] = (i == j) ? 1 : 0; + k++; + } + } +// display(inv, rows, rows); +// printf("\n"); + + /* First -- convert into upper triangular */ + for (i = 0; i < cols; i++) { + row_start = cols*i; + + /* Swap rows if we ave a zero i,i element. If we can't swap, then the + matrix was not invertible */ + + if (mat[row_start+i] == 0) { + for (j = i+1; j < rows && mat[cols*j+i] == 0; j++) ; + if (j == rows) return -1; + rs2 = j*cols; + for (k = 0; k < cols; k++) { + tmp = mat[row_start+k]; + mat[row_start+k] = mat[rs2+k]; + mat[rs2+k] = tmp; + tmp = inv[row_start+k]; + inv[row_start+k] = inv[rs2+k]; + inv[rs2+k] = tmp; + } + } + + /* Multiply the row by 1/element i,i */ + tmp = mat[row_start+i]; + if (tmp != 1) { + inverse = gf->divide.w64(gf,1, tmp); + for (j = 0; j < cols; j++) { + mat[row_start+j] = gf->multiply.w64(gf,mat[row_start+j], inverse); + inv[row_start+j] = gf->multiply.w64(gf,inv[row_start+j], inverse); + } + } + + /* Now for each j>i, add A_ji*Ai to Aj */ + k = row_start+i; + for (j = i+1; j != cols; j++) { + k += cols; + if (mat[k] != 0) { + if (mat[k] == 1) { + rs2 = cols*j; + for (x = 0; x < cols; x++) { + mat[rs2+x] ^= mat[row_start+x]; + inv[rs2+x] ^= inv[row_start+x]; + } + } else { + tmp = mat[k]; + rs2 = cols*j; + for (x = 0; x < cols; x++) { + mat[rs2+x] ^= gf->multiply.w64(gf,tmp, mat[row_start+x]); + inv[rs2+x] ^= gf->multiply.w64(gf,tmp, inv[row_start+x]); + } + } + } + } + } + + /* Now the matrix is upper triangular. Start at the top and multiply down */ + + for (i = rows-1; i >= 0; i--) { + row_start = i*cols; + for (j = 0; j < i; j++) { + rs2 = j*cols; + if (mat[rs2+i] != 0) { + tmp = mat[rs2+i]; + mat[rs2+i] = 0; + for (k = 0; k < cols; k++) { + inv[rs2+k] ^= gf->multiply.w64(gf,tmp, inv[row_start+k]); + } + } + } + } + +/* printf("mat\n"); + display(mat, rows, rows); + printf("\n"); + printf("inv\n"); + display(inv, rows, rows); + printf("\n"); +*/ + return 0; +} + + + + +int invertible_matrix(gf_t *gf, int *mat, int rows, int w) +{ + int cols, i, j, k, x, rs2; + int row_start; + mylong tmp, inverse; + + cols = rows; + + /* First -- convert into upper triangular */ + for (i = 0; i < cols; i++) { + row_start = cols*i; + + /* Swap rows if we ave a zero i,i element. If we can't swap, then the + matrix was not invertible */ + + if (mat[row_start+i] == 0) { + for (j = i+1; j < rows && mat[cols*j+i] == 0; j++) ; + if (j == rows) return 0; + rs2 = j*cols; + for (k = 0; k < cols; k++) { + tmp = mat[row_start+k]; + mat[row_start+k] = mat[rs2+k]; + mat[rs2+k] = tmp; + } + } + + /* Multiply the row by 1/element i,i */ + tmp = mat[row_start+i]; + if (tmp != 1) { + inverse = gf->divide.w64(gf,1, tmp); + for (j = 0; j < cols; j++) { + mat[row_start+j] = gf->multiply.w64(gf,mat[row_start+j], inverse); + } + } + + /* Now for each j>i, add A_ji*Ai to Aj */ + k = row_start+i; + for (j = i+1; j != cols; j++) { + k += cols; + if (mat[k] != 0) { + if (mat[k] == 1) { + rs2 = cols*j; + for (x = 0; x < cols; x++) { + mat[rs2+x] ^= mat[row_start+x]; + } + } else { + tmp = mat[k]; + rs2 = cols*j; + for (x = 0; x < cols; x++) { + mat[rs2+x] ^= gf->multiply.w64(gf,tmp,mat[row_start+x]); + } + } + } + } + } + return 1; +} + + + + + +mylong* readFullFile(int n, int t, mylong& sizeFile, mylong & padded_size) { + + ifstream stream("lena.png", ios::in | ios::binary | ios::ate); +// ifstream stream("lena_small.png", ios::in | ios::binary | ios::ate); +// ifstream stream("/home/couturie/Downloads/CARCARIASS.zip", ios::in | ios::binary | ios::ate); + + sizeFile=stream.tellg(); + std::cout << sizeFile << std::endl; + stream.seekg(0, ios::beg); + + + + + + + vector contents((istreambuf_iterator(stream)), istreambuf_iterator()); + + + + + + + + //make padding, we need to pad to be divisible by 8*t, we + if((sizeFile+8)%(8*t)!=0) { + cout<<(int)(sizeFile/(8*t))<(p_contents); + + padded_size=contents.size()/8; + + mylong *p_contents2=new mylong[padded_size]; + memcpy(p_contents2,p_contents,sizeof(mylong)*padded_size); + //mylong *p_contents2=(mylong*)p_contents; + + p_contents2[0]=sizeFile; + + + + +/* for(int i=0;i=0;i--) { + res<<=8; + res+=p_contents[i]; + } + + cout << "convert val " << (long)res << endl; + + res=0; + for(int i=16-1;i>=8;i--) { + res<<=8; + res+=p_contents[i]; + } + + cout << "convert val " << (long)res << endl; + */ + + return p_contents2; +} + +void sendChunk(string name,int cloud_id) { + stringstream ss; + ss <<"rclone copy "< elapsed_seconds = end-start; + std::cout << "elapsed time: " << elapsed_seconds.count() << "s\n"; + +// display(matC,t,t); + + + //Save trunks + for(int i=0;i myvector; + + // set some values: + for (int i=0; i=t;i--) { +// for(int i=0;i(&matS2[1]); + saveFile(reconstucted_data, "lena2.png",new_size); + return 0; +} + +