}
-Mat<byte> readFile(int n, int k, int& sizeFile, int &lc) {
+Mat<byte> 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<<sizeFile<<endl;
stream.seekg(0, ios::beg);
}
+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);
+ sizeFile=stream.tellg();
+ cout<<sizeFile<<endl;
+ stream.seekg(0, ios::beg);
+
+
+ lc=ceil(double(sizeFile)/k);
+ cout<<lc<<endl;
+
+ vector<uint8_t> contents2(k*lc,0);
+ vector<uint8_t> contents((istreambuf_iterator<char>(stream)), istreambuf_iterator<char>());
+ copy ( contents.begin(), contents.end(), contents2.begin() );
+
+
+
+
+ Mat<byte> matData(&contents2[0],1,contents2.size());
+
+ cout << "file size: " << contents2.size() << endl;
+
+ matData.reshape(k,lc);
+ cout<<matData.n_rows<<" "<<matData.n_cols<<endl;
+ return matData;
+}
+
+
+
+
void buildFullRankIDA(Cube<byte>& IDAmat, Cube<short> &invIDAmat, int q, int n, byte* DK) {
cout<<invIDAmat<<endl;
}
+void buildPartialRankIDA(Cube<byte>& 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<byte> rm1(RM1,1,1,q*n*k);
+ rm1.reshape(n,k,q);
+ IDAmat=rm1;
+/*
+ cout<<"rm1"<<endl;
+ cout<<rm1<<endl;
+
+
+
+
+// Construction of the IDA matrices
+ for(int i=0;i<q;i++) {
+ Mat<byte> sub(n,k);
+ sub.submat(0,0,n-1,k-1)=rm1.slice(i);
+
+
+ IDAmat.slice(i)=sub;
+
+
+ cout<<"det "<<i<<endl;
+ mat toto=conv_to<mat>::from(sub);
+ cout<<det(toto)<<endl;
+
+ }
+*/
+ cout<<IDAmat<<endl;
+
+}
+
+
int main( int argc, char *argv[] ) {
+
+ int full=0;
+
int q=2;
int n=4;
int k=4;
-// Initialization of IDA and inverse IDA matrix
- Cube<byte> IDAmat(n,n,q);
- Cube<short> invIDAmat(n,n,q);
- buildFullRankIDA(IDAmat, invIDAmat, q, n, &DK[0]);
-
- // rc4key(&DK[8], sc, 16);
-
+ int lc;
+ int sizeFile;
+ Mat<byte> M;
+ if(full)
+ M=readFullFile(n,k,sizeFile,lc);
+ else
+ M=readPartialFile(n,k,sizeFile,lc);
+
+ // cout<<"M "<<endl;
+ // cout<<M<<endl;
-
-
-
arma_rng::set_seed(time(NULL));
+// Initialization of IDA and inverse IDA matrix
+
+ Cube<byte> IDAmat;
+ Cube<short> 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<byte> M=readFile(n,k,sizeFile,lc);
// Ma<byte> data;
// data.load("/home/couturie/ajeter/lena.png");
cout<<C<<endl;
*/
-
- Mat<byte> C=IDAmat.slice(0)*M;
- M.save("M.bin",raw_binary);
-// Mat<short> D=invIDAmat.slice(0)*C;
+ Mat<byte> C;
+ Mat<char> D2;
+ C=IDAmat.slice(0)*M;
+ M.save("M.bin",raw_binary);
+
+ if(full) {
+ //Mat<short> D=invIDAmat.slice(0)*C;
- mat A=conv_to<mat>::from(IDAmat.slice(0).submat(0,0,k-1,n-1));
- mat B=conv_to<mat>::from(C.submat(0,0,k-1,lc-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;
+
- mat D=solve(A,B);
+ D2=conv_to<Mat<char>>::from(D);
+ }
+ 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));
+ mat D=solve(A,B);
+
+ cout<<D<<endl;
+ D2=conv_to<Mat<char>>::from(D);
+ }
- Mat<char> D2=conv_to<Mat<char>>::from(D);
+
// cout<<"D2"<<endl;
// cout<<D2<<endl;
// D2.save("D2.bin",raw_binary);