+//g++ test_sub_perm.cpp -o test_sub_perm -O3 -fpermissive
+
+
+// ./test_sub_perm sizebuf512 nb1000
+
+#include <string.h>
+#include <sys/time.h>
+#include<stdlib.h>
+#include<stdio.h>
+#include <iostream>
+
+
+using namespace std;
+
+typedef unsigned char uchar;
+
+
+
+int nb_test=1;
+int ctr=0;
+
+double time_encrypt=0;
+double time_decrypt=0;
+
+double TimeStart()
+{
+ struct timeval tstart;
+ gettimeofday(&tstart,0);
+ return( (double) (tstart.tv_sec + tstart.tv_usec*1e-6) );
+}
+
+double TimeStop(double t)
+{
+ struct timeval tend;
+
+ gettimeofday(&tend,0);
+ t = (double) (tend.tv_sec + tend.tv_usec*1e-6) - t;
+ return (t);
+}
+
+
+
+
+void rc4key(uchar *key, uchar *sc, int size_DK) {
+
+ for(int i=0;i<256;i++) {
+ sc[i]=i;
+ }
+
+
+ uchar j0 = 0;
+ for(int i0=0; i0<256; i0++) {
+ j0 = (j0 + sc[i0] + key[i0%size_DK] )&0xFF;
+ uchar tmp = sc[i0];
+ sc[i0] = sc[j0 ];
+ sc[j0] = tmp;
+ }
+}
+
+
+int main (int argc, char** argv)
+{
+ /* Set up the key and iv. Do I need to say to not hard code these in a
+ * real application? :-)
+ */
+
+ int size_buf=1;
+ int lena=0;
+
+
+ for(int i=1; i<argc; i++){
+ if(strncmp(argv[i],"nb",2)==0) nb_test = atoi(&(argv[i][2])); //nb of test
+ if(strncmp(argv[i],"sizebuf",7)==0) size_buf = atoi(&(argv[i][7])); //SIZE of the buffer
+ }
+
+
+
+ int size = 64;
+ uchar DK[size];
+ for(int i=0;i<size;i++) {
+ DK[i]=lrand48()&0xFF;
+ }
+
+
+
+ int width;
+ int height;
+ int imsize;
+ uchar *buffer;
+ uchar Sbox1[256];
+ rc4key(DK, Sbox1, 8);
+
+
+ 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
+ for(int i=0;i<oneD;i++) {
+ plaintext[i]=buffer[i];
+ }
+
+
+
+ uchar *ciphertext = malloc(imsize+1000); //add that for cbc
+
+ /* Buffer for the decrypted text */
+ uchar *decryptedtext = malloc(imsize+1000); //add that for cbc
+
+ int decryptedtext_len, ciphertext_len;
+
+ double t=TimeStart();
+ for(int i=0;i<nb_test;i++)
+ {
+
+ for(int j=0;j<imsize;j++)
+ plaintext[j]=Sbox1[plaintext[j]];
+
+ }
+ double time=TimeStop(t);
+ cout<<"Throughput Sbox \t";
+ cout<<(double)imsize*nb_test/time<<"\t";
+
+
+
+ return 0;
+}