+void encrypt_ctr(uchar* seq_in, uchar *seq_out, int len,uchar* RM1,int *Pbox, int *PboxRM, uchar *Sbox1, uchar *Sbox2, int enc) {
+
+
+ uchar *X=new uchar[h2];
+ uchar *fX=new uchar[h2];
+ int ind1,ind2;
+
+
+ for(int a=0;a<h2;a++) {
+ X[a]=Sbox1[a&0xFF]; //Warning according to the size of h2, we can be outsize of Sbox1[a]
+ }
+
+
+ for(int it=0;it<len;it++) {
+ if(enc) {
+ ind1=it*h2;
+ ind2=Pbox[it]*h2;
+ }
+ else {
+ ind2=it*h2;
+ ind1=Pbox[it]*h2;
+ }
+
+
+
+ /*for(int a=0;a<h2;a+=4){
+ fX[a]=RM1[X[a]];
+ fX[a+1]=RM1[X[a+1]];
+ fX[a+2]=RM1[X[a+2]];
+ fX[a+3]=RM1[X[a+3]];
+ }*/
+
+ for(int a=0;a<h2;a+=4){
+ fX[a]=X[a];
+ fX[a+1]=X[a+1];
+ fX[a+2]=X[a+2];
+ fX[a+3]=X[a+3];
+ }
+
+ /* if(it<513) {
+ for(int a=0;a<h2;a++)
+ printf("%d ",fX[a]);
+ printf("\n");
+ }*/
+
+ *(int*)&fX[0]=it;
+
+ /* if(it<513) {
+ for(int a=0;a<h2;a++)
+ printf("%d ",fX[a]);
+ printf("\n");
+ }*/
+
+ for(int a=0;a<h2;a+=4) {
+ fX[a]=fX[a]^RM1[a];
+ fX[a+1]=fX[a+1]^RM1[a+1];
+ fX[a+2]=fX[a+2]^RM1[a+2];
+ fX[a+3]=fX[a+3]^RM1[a+3];
+ }
+
+
+ for(int a=0;a<h2;a+=4) {
+ fX[a]=Sbox2[fX[a]];
+ fX[a+1]=Sbox2[fX[a+1]];
+ fX[a+2]=Sbox2[fX[a+2]];
+ fX[a+3]=Sbox2[fX[a+3]];
+ }
+
+ for(int a=0;a<h2;a+=4) {
+ fX[a]=fX[a]^seq_in[ind2+a];
+ fX[a+1]=fX[a+1]^seq_in[ind2+a+1];
+ fX[a+2]=fX[a+2]^seq_in[ind2+a+2];
+ fX[a+3]=fX[a+3]^seq_in[ind2+a+3];
+ }
+
+
+ for(int a=0;a<h2;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];
+ }
+
+ for(int a=0;a<h2;a+=4) {
+ RM1[a]=RM1[PboxRM[a]];
+ RM1[a+1]=RM1[PboxRM[a+1]];
+ RM1[a+2]=RM1[PboxRM[a+2]];
+ RM1[a+3]=RM1[PboxRM[a+3]];
+ }
+
+
+
+ }
+
+
+}
+