}
}
+void rc4keyperm(uchar *key,int len, int rp,int *sc, int size_DK) {
+
+ //sc=1:len;
+
+
+
+ for (int i=0;i<len;i++) {
+ sc[i]=i;
+ }
+ for (int it = 0; it < rp; it++) {
+ int j0 = 1;
+ for(int i0 = 0; i0<len; i0++) {
+ j0 = (j0 + sc[i0] + sc[j0] + key[i0%size_DK] )% len;
+ int tmp = sc[i0];
+ sc[i0] = sc[j0];
+ sc[j0] = tmp;
+ }
+
+ }
+}
+
+
+
int main (int argc, char** argv)
{
int width;
int height;
int imsize;
+ width=size_buf;
+ height=size_buf;
+
+ imsize=width*height;
uchar *buffer;
uchar Sbox1[256];
rc4key(DK, Sbox1, 8);
+ int *Pbox=new int[imsize];
+ rc4keyperm(&DK[32], imsize, 1, Pbox, 32);
+
+
-
- width=size_buf;
- height=size_buf;
- imsize=width*height;
buffer=malloc(imsize*sizeof(uchar));
for(int i=0;i<imsize;i++) {
buffer[i]=lrand48();
int oneD=width*height;
uchar *plaintext = malloc(imsize+1000); //add that for cbc
+ uchar *plaintext2 = malloc(imsize+1000); //add that for cbc
+
for(int i=0;i<oneD;i++) {
plaintext[i]=buffer[i];
+ plaintext2[i]=buffer[i];
}
cout<<"Throughput Sbox \t";
cout<<(double)imsize*nb_test/time<<"\t";
+ t=TimeStart();
+ for(int i=0;i<nb_test;i++)
+ {
+ for(int j=0;j<imsize;j++)
+ plaintext2[j]=plaintext[Pbox[j]];
+
+ }
+ time=TimeStop(t);
+ cout<<"Throughput Pbox \t";
+ cout<<(double)imsize*nb_test/time<<"\t";
+ t=TimeStart();
+ for(int i=0;i<nb_test;i++)
+ {
+
+ for(int j=0;j<imsize;j++)
+ plaintext2[j]=Sbox1[plaintext[Pbox[j]]];
+
+ }
+ time=TimeStop(t);
+ cout<<"Throughput Sbox and Pbox \t";
+ cout<<(double)imsize*nb_test/time<<"\t";
+
+
return 0;
}