]> AND Private Git Repository - Cipher_code.git/blobdiff - OneRoundIoT/EnhancedOneRound/enhanced_oneround.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
new
[Cipher_code.git] / OneRoundIoT / EnhancedOneRound / enhanced_oneround.cpp
index 22a7a90fbb3270021aaaf0827a7cfb935873748a..13971e60b22db3b67570d24aaaabe918c591492d 100644 (file)
@@ -38,7 +38,7 @@ int ecbprng=0;
 
 
 
-
+typedef __uint64_t mylong;
 
 
 typedef unsigned char   uchar;
@@ -73,18 +73,22 @@ uint xorshift32(const uint t)
   return x;
 }
 
-ulong xorshift64(ulong t)
+
+mylong xorseed;
+
+mylong xorshift64()
 {
         /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
-        ulong x = t;
+        mylong x = xorseed;
         x ^= x >> 12; // a
         x ^= x << 25; // b
         x ^= x >> 27; // c
 
 
-        return x;
+        return xorseed=x;
 }
 
+/*
 __uint128_t g_lehmer64_state;
 
 inline uint64_t splitmix64_stateless(uint64_t index) {
@@ -106,7 +110,7 @@ inline uint64_t lehmer64() {
   return g_lehmer64_state >> 64;
 }
 
-
+*/
 
 
 
@@ -187,17 +191,19 @@ void prga(uchar *sc, int ldata, uchar *r) {
 
 
 template<int h>
-void encrypt_ecb_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, ulong myrand, int debug) {
+void encrypt_ecb_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar* IV,mylong myrand, int debug) {
 
   uchar X[h];
   uchar Y[h];
   uchar fX[h];
   uchar gY[h];
-  uchar RM1[h];
-  uchar RM2[h];
+  uchar *RM1=&RM[0];
+  uchar *RM2=&RM[h];
   uchar tmp[h];
-  ulong *rm1=(ulong*)RM1;
-  ulong *rm2=(ulong*)RM2;
+  mylong *rm1=(mylong*)RM1;
+  mylong *rm2=(mylong*)RM2;
+
+  
   
   for(int it=0;it<len/2;it++) {
     int ind1=Pbox[it]*h;
@@ -205,9 +211,9 @@ void encrypt_ecb_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbo
 
     
     for(int a=0;a<(h>>3);a++) {
-      myrand=lehmer64();
+      myrand=xorshift64();
       rm1[a]=myrand;
-      myrand=lehmer64();
+      myrand=xorshift64();
       rm2[a]=myrand;
     }  
 
@@ -313,7 +319,7 @@ void encrypt_ecb_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbo
 
 
 template<int h>
-void decrypt_ecb_prng(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2,  ulong myrand, int debug) {
+void decrypt_ecb_prng(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2,  uchar* IV,mylong myrand, int debug) {
 
   uchar invfX[h];
   uchar invgY[h];
@@ -322,8 +328,9 @@ void decrypt_ecb_prng(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pb
   uchar RM1[h];
   uchar RM2[h];
   uchar tmp[h];
-  ulong *rm1=(ulong*)RM1;
-  ulong *rm2=(ulong*)RM2;
+  mylong *rm1=(mylong*)RM1;
+  mylong *rm2=(mylong*)RM2;
+
   
   for(int it=0;it<len/2;it++) {
     int ind1=Pbox[it]*h;
@@ -331,9 +338,9 @@ void decrypt_ecb_prng(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pb
 
 
     for(int a=0;a<(h>>3);a++) {
-      myrand=lehmer64();
+      myrand=xorshift64();
       rm1[a]=myrand;
-      myrand=lehmer64();
+      myrand=xorshift64();
       rm2[a]=myrand;
     }
 
@@ -439,30 +446,49 @@ void decrypt_ecb_prng(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pb
 
 
 template<int h>
-void encrypt_ecb_rm(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, ulong myrand, int debug) {
+void encrypt_ecb_rm(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *IV, int debug) {
 
   uchar X[h];
   uchar Y[h];
   uchar fX[h];
   uchar gY[h];
-  uchar RM1[h];
-  uchar RM2[h];
+  uchar IV1[h];
+  uchar IV2[h];
+  uchar *RM1;
+  uchar *RM2;
   uchar tmp[h];
-  ulong *rm1=(ulong*)RM1;
-  ulong *rm2=(ulong*)RM2;
+
+
+
+  for(int a=0;a<h;a+=4) {
+    IV1[a]=IV[a];
+    IV1[a+1]=IV[a+1];
+    IV1[a+2]=IV[a+2];
+    IV1[a+3]=IV[a+3];
+  }
+
+
+  for(int a=0;a<h;a+=4) {
+    IV2[a]=IV[h+a];
+    IV2[a+1]=IV[h+a+1];
+    IV2[a+2]=IV[h+a+2];
+    IV2[a+3]=IV[h+a+3];
+
+  }
+
+
+
+
+
   
   for(int it=0;it<len/2;it++) {
     int ind1=Pbox[it]*h;
     int ind2=Pbox[it+len/2]*h;
 
-    
-    for(int a=0;a<(h>>3);a++) {
-      myrand=lehmer64();
-      rm1[a]=myrand;
-      myrand=lehmer64();
-      rm2[a]=myrand;
-    }  
 
+    RM1=&RM[PboxSRM[it]*h];
+    RM2=&RM[h*h+PboxSRM[len/2-it]*h];
+    
 
   
     for(int a=0;a<h;a+=4) {
@@ -565,29 +591,45 @@ void encrypt_ecb_rm(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox,
 
 
 template<int h>
-void decrypt_ecb_rm(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2,  ulong myrand, int debug) {
+void decrypt_ecb_rm(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2,  uchar *IV, int debug) {
 
   uchar invfX[h];
   uchar invgY[h];
   uchar fX[h];
   uchar gY[h];
-  uchar RM1[h];
-  uchar RM2[h];
+  uchar IV1[h];
+  uchar IV2[h];
+  uchar *RM1;
+  uchar *RM2;
   uchar tmp[h];
-  ulong *rm1=(ulong*)RM1;
-  ulong *rm2=(ulong*)RM2;
+
+  
+
+  for(int a=0;a<h;a+=4) {
+    IV1[a]=IV[a];
+    IV1[a+1]=IV[a+1];
+    IV1[a+2]=IV[a+2];
+    IV1[a+3]=IV[a+3];
+  }
+
+
+  for(int a=0;a<h;a+=4) {
+    IV2[a]=IV[h+a];
+    IV2[a+1]=IV[h+a+1];
+    IV2[a+2]=IV[h+a+2];
+    IV2[a+3]=IV[h+a+3];
+
+  }
+
+
   
   for(int it=0;it<len/2;it++) {
     int ind1=Pbox[it]*h;
     int ind2=Pbox[it+len/2]*h;
 
 
-    for(int a=0;a<(h>>3);a++) {
-      myrand=lehmer64();
-      rm1[a]=myrand;
-      myrand=lehmer64();
-      rm2[a]=myrand;
-    }
+    RM1=&RM[PboxSRM[it]*h];
+    RM2=&RM[h*h+PboxSRM[len/2-it]*h];
 
 
     
@@ -687,82 +729,6 @@ void decrypt_ecb_rm(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox
 
 
 
-/*
-
-template<int h>
-void encrypt_ecb(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uint myrand, int debug) {
-
-  uchar X[h];
-  uchar Y[h];
-  uchar fX[h];
-  uchar gY[h];
-  uchar *RM1;
-  uchar *RM2;
-  
-  for(int it=0;it<len/2;it++) {
-    int ind1=Pbox[it]*h;
-    int ind2=Pbox[it+len/2]*h;
-
-
-
-    RM1=&RM[PboxSRM[it]*h];
-    RM2=&RM[h*h+PboxSRM[it]*h];
-
-    
-    for(int a=0;a<h;a+=4) {
-      X[a]=seq_in[ind2+a];
-      X[a+1]=seq_in[ind2+a+1];
-      X[a+2]=seq_in[ind2+a+2];
-      X[a+3]=seq_in[ind2+a+3];
-    }
-
-    for(int a=0;a<h;a+=4) {
-      Y[a]=seq_in[ind1+a];
-      Y[a+1]=seq_in[ind1+a+1];
-      Y[a+2]=seq_in[ind1+a+2];
-      Y[a+3]=seq_in[ind1+a+3];
-    }
-
-
-    for(int a=0;a<h;a+=4) {
-      fX[a]=Sbox2[Sbox1[X[a]^RM1[a]]^Y[a]];
-      fX[a+1]=Sbox2[Sbox1[X[a+1]^RM1[a+1]]^Y[a+1]];
-      fX[a+2]=Sbox2[Sbox1[X[a+2]^RM1[a+2]]^Y[a+2]];
-      fX[a+3]=Sbox2[Sbox1[X[a+3]^RM1[a+3]]^Y[a+3]];
-    }
-
-    for(int a=0;a<h;a+=4) {
-      gY[a]=Sbox1[Sbox2[fX[a]^Y[a]]^RM2[a]];
-      gY[a+1]=Sbox1[Sbox2[fX[a+1]^Y[a+1]]^RM2[a+1]];
-      gY[a+2]=Sbox1[Sbox2[fX[a+2]^Y[a+2]]^RM2[a+2]];
-      gY[a+3]=Sbox1[Sbox2[fX[a+3]^Y[a+3]]^RM2[a+3]];
-
-    }     
-
-    for(int a=0;a<h;a+=4) {
-      seq_out[ind2+a]=gY[a];
-      seq_out[ind2+a+1]=gY[a+1];
-      seq_out[ind2+a+2]=gY[a+2];
-      seq_out[ind2+a+3]=gY[a+3];
-    }
-
-    for(int a=0;a<h;a+=4) {
-      seq_out[ind1+a]=fX[a];
-      seq_out[ind1+a+1]=fX[a+1];
-      seq_out[ind1+a+2]=fX[a+2];
-      seq_out[ind1+a+3]=fX[a+3];
-    }
-
-
-
-  }
-  
-
-
-
-}
-
-
 
 
 
@@ -770,87 +736,7 @@ void encrypt_ecb(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, in
 
 
 template<int h>
-void decrypt_ecb(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2,  uint myrand, int debug) {
-
-  uchar invfX[h];
-  uchar invgY[h];
-  uchar fX[h];
-  uchar gY[h];
-  uchar *RM1;
-  uchar *RM2;
-  
-  for(int it=0;it<len/2;it++) {
-    int ind1=Pbox[it]*h;
-    int ind2=Pbox[it+len/2]*h;
-
-
-    RM1=&RM[PboxSRM[it]*h];
-    RM2=&RM[h*h+PboxSRM[it]*h];
-
-    
-    for(int a=0;a<h;a+=4) {
-      gY[a]=seq_in[ind2+a];
-      gY[a+1]=seq_in[ind2+a+1];
-      gY[a+2]=seq_in[ind2+a+2];
-      gY[a+3]=seq_in[ind2+a+3];
-    }
-
-    for(int a=0;a<h;a+=4) {
-      fX[a]=seq_in[ind1+a];
-      fX[a+1]=seq_in[ind1+a+1];
-      fX[a+2]=seq_in[ind1+a+2];
-      fX[a+3]=seq_in[ind1+a+3];
-    }
-
-    for(int a=0;a<h;a+=4) {
-      invgY[a]=Inv_Sbox2[Inv_Sbox1[gY[a]]^RM2[a]]^fX[a];
-      invgY[a+1]=Inv_Sbox2[Inv_Sbox1[gY[a+1]]^RM2[a+1]]^fX[a+1];
-      invgY[a+2]=Inv_Sbox2[Inv_Sbox1[gY[a+2]]^RM2[a+2]]^fX[a+2];
-      invgY[a+3]=Inv_Sbox2[Inv_Sbox1[gY[a+3]]^RM2[a+3]]^fX[a+3];
-    }     
-
-
-    
-    for(int a=0;a<h;a+=4) {
-      invfX[a]=Inv_Sbox1[Inv_Sbox2[fX[a]]^invgY[a]]^RM1[a];
-      invfX[a+1]=Inv_Sbox1[Inv_Sbox2[fX[a+1]]^invgY[a+1]]^RM1[a+1];
-      invfX[a+2]=Inv_Sbox1[Inv_Sbox2[fX[a+2]]^invgY[a+2]]^RM1[a+2];
-      invfX[a+3]=Inv_Sbox1[Inv_Sbox2[fX[a+3]]^invgY[a+3]]^RM1[a+3];
-
-    }
-
-
-    for(int a=0;a<h;a+=4) {
-      seq_out[ind2+a]=invfX[a];
-      seq_out[ind2+a+1]=invfX[a+1];
-      seq_out[ind2+a+2]=invfX[a+2];
-      seq_out[ind2+a+3]=invfX[a+3];
-    }
-
-    for(int a=0;a<h;a+=4) {
-      seq_out[ind1+a]=invgY[a];
-      seq_out[ind1+a+1]=invgY[a+1];
-      seq_out[ind1+a+2]=invgY[a+2];
-      seq_out[ind1+a+3]=invgY[a+3];
-    }
-
-
-
-  }
-  
-
-
-
-}
-
-*/
-
-
-
-
-
-template<int h>
-void encrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uint myrand, int debug) {
+void encrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *IV,uint myrand, int debug) {
 
   uchar X[h];
   uchar Y[h];
@@ -861,8 +747,27 @@ void encrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbo
   uchar RM1[h];
   uchar RM2[h];
   uchar tmp[h];
-  ulong *rm1=(ulong*)RM1;
-  ulong *rm2=(ulong*)RM2;
+  mylong *rm1=(mylong*)RM1;
+  mylong *rm2=(mylong*)RM2;
+
+
+  
+  for(int a=0;a<h;a+=4) {
+    IV1[a]=IV[a];
+    IV1[a+1]=IV[a+1];
+    IV1[a+2]=IV[a+2];
+    IV1[a+3]=IV[a+3];
+  }
+
+
+  for(int a=0;a<h;a+=4) {
+    IV2[a]=IV[h+a];
+    IV2[a+1]=IV[h+a+1];
+    IV2[a+2]=IV[h+a+2];
+    IV2[a+3]=IV[h+a+3];
+
+  }
+
   
   for(int it=0;it<len/2;it++) {
     int ind1=Pbox[it]*h;
@@ -870,9 +775,9 @@ void encrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbo
 
     
     for(int a=0;a<(h>>3);a++) {
-      myrand=lehmer64();
+      myrand=xorshift64();
       rm1[a]=myrand;
-      myrand=lehmer64();
+      myrand=xorshift64();
       rm2[a]=myrand;
     }  
 
@@ -908,7 +813,7 @@ void encrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbo
     }
 
     
-    /*for(int a=0;a<h;a+=4) {
+    /* for(int a=0;a<h;a+=4) {
       tmp[a]=Sbox1[X[a]^RM1[a]^IV1[a]];
       tmp[a+1]=Sbox1[X[a+1]^RM1[a+1]^IV1[a+1]];
       tmp[a+2]=Sbox1[X[a+2]^RM1[a+2]^IV1[a+2]];
@@ -920,16 +825,16 @@ void encrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbo
       fX[a+1]=Sbox2[tmp[a+1]^Y[a+1]];
       fX[a+2]=Sbox2[tmp[a+2]^Y[a+2]];
       fX[a+3]=Sbox2[tmp[a+3]^Y[a+3]];
-    }
+      }
 
-    /*
-    for(int a=0;a<h;a+=4) {
+    
+    /*for(int a=0;a<h;a+=4) {
       fX[a]=Sbox2[Sbox1[X[a]^RM1[a]^IV1[a]]^Y[a]];
       fX[a+1]=Sbox2[Sbox1[X[a+1]^RM1[a+1]^IV1[a+1]]^Y[a+1]];
       fX[a+2]=Sbox2[Sbox1[X[a+2]^RM1[a+2]^IV1[a+2]]^Y[a+2]];
       fX[a+3]=Sbox2[Sbox1[X[a+3]^RM1[a+3]^IV1[a+3]]^Y[a+3]];
-      }*/
-
+      }
+    */
 
  for(int a=0;a<h;a+=4) {
       tmp[a]=fX[a]^Y[a]^IV2[a];
@@ -947,7 +852,7 @@ void encrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbo
 
     }     
 
- /*
   /*
     for(int a=0;a<h;a+=4) {
       tmp[a]=Sbox2[fX[a]^Y[a]^IV2[a]];
       tmp[a+1]=Sbox2[fX[a+1]^Y[a+1]^IV2[a+1]];
@@ -955,7 +860,7 @@ void encrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbo
       tmp[a+3]=Sbox2[fX[a+3]^Y[a+3]^IV2[a+3]];
 
     }     
- */
+    */ 
 
     for(int a=0;a<h;a+=4) {
       gY[a]=Sbox1[tmp[a]^RM2[a]];
@@ -967,7 +872,7 @@ void encrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbo
 
 
 
-    /*
+/*    
     for(int a=0;a<h;a+=4) {
       gY[a]=Sbox1[Sbox2[fX[a]^Y[a]^IV2[a]]^RM2[a]];
       gY[a+1]=Sbox1[Sbox2[fX[a+1]^Y[a+1]^IV2[a+1]]^RM2[a+1]];
@@ -975,7 +880,7 @@ void encrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbo
       gY[a+3]=Sbox1[Sbox2[fX[a+3]^Y[a+3]^IV2[a+3]]^RM2[a+3]];
 
     } 
-    */    
+*/  
 
     for(int a=0;a<h;a+=4) {
       seq_out[ind2+a]=gY[a];
@@ -1019,19 +924,38 @@ void encrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbo
 
 
 template<int h>
-void decrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2,  uint myrand, int debug) {
+void decrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2, uchar* IV, uint myrand, int debug) {
 
   uchar invfX[h];
   uchar invgY[h];
   uchar fX[h];
   uchar gY[h];
-  uchar IV1[h];
-  uchar IV2[h];
   uchar RM1[h];
   uchar RM2[h];
+  uchar IV1[h];
+  uchar IV2[h];
   uchar tmp[h];
-  ulong *rm1=(ulong*)RM1;
-  ulong *rm2=(ulong*)RM2;
+  mylong *rm1=(mylong*)RM1;
+  mylong *rm2=(mylong*)RM2;
+
+
+  
+  for(int a=0;a<h;a+=4) {
+    IV1[a]=IV[a];
+    IV1[a+1]=IV[a+1];
+    IV1[a+2]=IV[a+2];
+    IV1[a+3]=IV[a+3];
+  }
+
+
+  for(int a=0;a<h;a+=4) {
+    IV2[a]=IV[h+a];
+    IV2[a+1]=IV[h+a+1];
+    IV2[a+2]=IV[h+a+2];
+    IV2[a+3]=IV[h+a+3];
+
+  }
+
   
   for(int it=0;it<len/2;it++) {
     int ind1=Pbox[it]*h;
@@ -1039,9 +963,9 @@ void decrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pb
 
     
     for(int a=0;a<(h>>3);a++) {
-      myrand=lehmer64();
+      myrand=xorshift64();
       rm1[a]=myrand;
-      myrand=lehmer64();
+      myrand=xorshift64();
       rm2[a]=myrand;
     }  
     
@@ -1085,6 +1009,16 @@ void decrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pb
     }   
 
 
+/*
+ for(int a=0;a<h;a+=4) {
+      invgY[a]=Inv_Sbox2[Inv_Sbox1[gY[a]]^RM2[a]]^fX[a]^IV2[a];
+      invgY[a+1]=Inv_Sbox2[Inv_Sbox1[gY[a+1]]^RM2[a+1]]^fX[a+1]^IV2[a+1];
+      invgY[a+2]=Inv_Sbox2[Inv_Sbox1[gY[a+2]]^RM2[a+2]]^fX[a+2]^IV2[a+2];
+      invgY[a+3]=Inv_Sbox2[Inv_Sbox1[gY[a+3]]^RM2[a+3]]^fX[a+3]^IV2[a+3];
+    }   
+*/
+
+    
     for(int a=0;a<h;a+=4) {
       tmp[a]=Inv_Sbox2[fX[a]]^invgY[a];
       tmp[a+1]=Inv_Sbox2[fX[a+1]]^invgY[a+1];
@@ -1113,6 +1047,18 @@ void decrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pb
 
     }
 
+/*
+ for(int a=0;a<h;a+=4) {
+      invfX[a]=Inv_Sbox1[Inv_Sbox2[fX[a]]^invgY[a]]^RM1[a]^IV1[a];
+      invfX[a+1]=Inv_Sbox1[Inv_Sbox2[fX[a+1]]^invgY[a+1]]^RM1[a+1]^IV1[a+1];
+      invfX[a+2]=Inv_Sbox1[Inv_Sbox2[fX[a+2]]^invgY[a+2]]^RM1[a+2]^IV1[a+2];
+      invfX[a+3]=Inv_Sbox1[Inv_Sbox2[fX[a+3]]^invgY[a+3]]^RM1[a+3]^IV1[a+3];
+
+    }
+
+*/
+
+    
 
     for(int a=0;a<h;a+=4) {
       seq_out[ind2+a]=invfX[a];
@@ -1898,8 +1844,8 @@ int main(int argc, char** argv) {
   uchar RM[h*h*2+256];
   uchar IV[2*h];
 
-  ulong myrand=0;
-
+  mylong myrand=0;
 
   double time_encrypt=0;
   double time_decrypt=0;
@@ -1958,8 +1904,8 @@ int main(int argc, char** argv) {
   inverse_tables(Sbox2,256,Inv_Sbox2);
 
 
-
-  lehmer64_seed(myrand);
+  xorseed=myrand;
+//  lehmer64_seed(myrand);
   time_encrypt=0;
   t=TimeStart();
 
@@ -1969,65 +1915,65 @@ int main(int argc, char** argv) {
     for(i=0;i<nb_test;i++)
     {
       if(cbcprng)
-       encrypt_cbc_prng<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_cbc_prng<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
       if(cbcrm)
        encrypt_cbc_rm<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
       if(ecbrm)
-       encrypt_ecb_rm<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_ecb_rm<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
       if(ecbprng)
-       encrypt_ecb_prng<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_ecb_prng<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
     }
     break;
   case 8: 
     for(i=0;i<nb_test;i++)
     {
       if(cbcprng)
-       encrypt_cbc_prng<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_cbc_prng<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
       if(cbcrm)
        encrypt_cbc_rm<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
       if(ecbrm)
-       encrypt_ecb_rm<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_ecb_rm<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
       if(ecbprng)
-       encrypt_ecb_prng<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_ecb_prng<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
     }
     break;
   case 16: 
     for(i=0;i<nb_test;i++)
     {
       if(cbcprng)
-       encrypt_cbc_prng<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_cbc_prng<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
       if(cbcrm)
        encrypt_cbc_rm<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
       if(ecbrm)
-       encrypt_ecb_rm<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_ecb_rm<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
       if(ecbprng)
-       encrypt_ecb_prng<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_ecb_prng<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
     }
     break;
   case 32: 
     for(i=0;i<nb_test;i++)
     {
       if(cbcprng)
-       encrypt_cbc_prng<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_cbc_prng<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
       if(cbcrm)
        encrypt_cbc_rm<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
       if(ecbrm)
-       encrypt_ecb_rm<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_ecb_rm<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
       if(ecbprng)
-       encrypt_ecb_prng<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_ecb_prng<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
     }
     break;
   case 64: 
     for(i=0;i<nb_test;i++)
     {
       if(cbcprng)
-       encrypt_cbc_prng<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_cbc_prng<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
       if(cbcrm)
        encrypt_cbc_rm<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
       if(ecbrm)
-       encrypt_ecb_rm<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_ecb_rm<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
       if(ecbprng)
-       encrypt_ecb_prng<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_ecb_prng<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
       
     }
     break;
@@ -2035,13 +1981,13 @@ int main(int argc, char** argv) {
     for(i=0;i<nb_test;i++)
     {
       if(cbcprng)
-       encrypt_cbc_prng<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_cbc_prng<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
       if(cbcrm)
        encrypt_cbc_rm<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
       if(ecbrm)
-       encrypt_ecb_rm<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_ecb_rm<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
       if(ecbprng)
-       encrypt_ecb_prng<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_ecb_prng<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
       
     }
     break;
@@ -2049,13 +1995,13 @@ int main(int argc, char** argv) {
     for(i=0;i<nb_test;i++)
     {
       if(cbcprng)
-       encrypt_cbc_prng<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_cbc_prng<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
       if(cbcrm)
        encrypt_cbc_rm<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
       if(ecbrm)
-       encrypt_ecb_rm<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_ecb_rm<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
       if(ecbprng)
-       encrypt_ecb_prng<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
+       encrypt_ecb_prng<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
       
     }
     break;
@@ -2074,93 +2020,94 @@ int main(int argc, char** argv) {
     store_RGB_pixmap("lena2.ppm", data_R, data_G, data_B, width, height);
   }
 
-  
-  lehmer64_seed(myrand);
+
+  xorseed=myrand;
+  // lehmer64_seed(myrand);
   time_decrypt=0;
   t=TimeStart();
   switch(h) {
   case 4:
     for(i=0;i<nb_test;i++) {
       if(cbcprng)
-       decrypt_cbc_prng<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_cbc_prng<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
       if(cbcrm)
        decrypt_cbc_rm<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
       if(ecbrm)
-       decrypt_ecb_rm<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_ecb_rm<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
       if(ecbprng)
-       decrypt_ecb_prng<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_ecb_prng<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
     }
     break;
   case 8:
     for(i=0;i<nb_test;i++) {
       if(cbcprng)
-       decrypt_cbc_prng<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_cbc_prng<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
       if(cbcrm)
        decrypt_cbc_rm<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
       if(ecbrm)
-       decrypt_ecb_rm<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_ecb_rm<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
       if(ecbprng)
-       decrypt_ecb_prng<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_ecb_prng<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
     }
     break;
   case 16:
     for(i=0;i<nb_test;i++) {
       if(cbcprng)
-       decrypt_cbc_prng<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_cbc_prng<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
       if(cbcrm)
        decrypt_cbc_rm<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
       if(ecbrm)
-       decrypt_ecb_rm<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_ecb_rm<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
       if(ecbprng)
-       decrypt_ecb_prng<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_ecb_prng<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
     }
     break;
   case 32:
     for(i=0;i<nb_test;i++) {
       if(cbcprng)
-       decrypt_cbc_prng<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_cbc_prng<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
       if(cbcrm)
        decrypt_cbc_rm<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
       if(ecbrm)
-       decrypt_ecb_rm<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_ecb_rm<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
       if(ecbprng)
-       decrypt_ecb_prng<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_ecb_prng<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
     }
     break;
   case 64:
     for(i=0;i<nb_test;i++) {
       if(cbcprng)
-       decrypt_cbc_prng<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_cbc_prng<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
       if(cbcrm)
        decrypt_cbc_rm<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
       if(ecbrm)
-       decrypt_ecb_rm<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_ecb_rm<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
       if(ecbprng)
-       decrypt_ecb_prng<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_ecb_prng<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
     }
     break;
   case 128:
     for(i=0;i<nb_test;i++) {
       if(cbcprng)
-       decrypt_cbc_prng<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_cbc_prng<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
       if(cbcrm)
        decrypt_cbc_rm<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
       if(ecbrm)
-       decrypt_ecb_rm<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_ecb_rm<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
       if(ecbprng)
-       decrypt_ecb_prng<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_ecb_prng<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
     }
     break;
   case 256:
     for(i=0;i<nb_test;i++) {
       if(cbcprng)
-       decrypt_cbc_prng<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_cbc_prng<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
       if(cbcrm)
        decrypt_cbc_rm<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
       if(ecbrm)
-       decrypt_ecb_rm<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_ecb_rm<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
       if(ecbprng)
-       decrypt_ecb_prng<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
+       decrypt_ecb_prng<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
     }
     break;
   }
@@ -2189,6 +2136,5 @@ int main(int argc, char** argv) {
   }
   
 
-
   return 0;
 }