#include<string.h>
#include <fstream>
#include <sys/time.h>
+#include <glib.h>
+
/*#include <cryptopp/hex.h>
#include <cryptopp/sha.h>
int ind1,ind2;
- for(int a=0;a<h2;a++) {
+ for(int a=0;a<h2;a+=4) {
X[a]=Sbox1[a&0xFF]; //Warning according to the size of h2, we can be outsize of Sbox1[a]
+ X[a+1]=Sbox1[(a+1)&0xFF];
+ X[a+2]=Sbox1[(a+2)&0xFF];
+ X[a+3]=Sbox1[(a+3)&0xFF];
}
}
-
- /*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];
+ for(int a=0;a<h2;a+=4) {
+ X[a]=Sbox1[X[a]];
+ X[a+1]=Sbox1[X[a+1]];
+ X[a+2]=Sbox1[X[a+2]];
+ X[a+3]=Sbox1[X[a+3]];
}
-
+
- *(int*)&fX[0]^=it;
+// *(int*)&fX[0]^=it;
/* for(int a=0;a<h2;a+=16) {
*(int*)&fX[a+4]^=it;
*(int*)&fX[a+8]^=it;
*(int*)&fX[a+12]^=it;
- }
-*/
+ }
+*/
+
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];
+ fX[a]=X[a]^RM1[a];
+ fX[a+1]=X[a+1]^RM1[a+1];
+ fX[a+2]=X[a+2]^RM1[a+2];
+ fX[a+3]=X[a+3]^RM1[a+3];
}
- for(int a=0;a<h2;a+=4) {
+ /* 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];
uchar *data_R, *data_G, *data_B;
int imsize;
uchar *buffer;
+
+
+
+
if(lena==1) {
load_RGB_pixmap("lena.ppm", &width, &height, &data_R, &data_G, &data_B);
+// load_RGB_pixmap("8192.ppm", &width, &height, &data_R, &data_G, &data_B);
imsize=width*height*3;
// load_RGB_pixmap("No_ecb_mode_picture.ppm", &width, &height, &data_R, &data_G, &data_B);
}
for (int i = 0; i < 256 ; i++) {
mix[i]=Secretkey[i]^counter[i];
+
}
+ gchar *sha512;
+
+ sha512 = g_compute_checksum_for_string(G_CHECKSUM_SHA512, (const char*) mix, 256);
+// g_print("%s\n", sha512);
+
+
+
+
+
+
+
// cout<<"hash "<<endl;
for (int i = 0; i < 64 ; i++) {
// DK[i]=digest[i];
- DK[i]=mix[i];
+ DK[i]=sha512[i];
}
-
+ g_free(sha512);
int *Pbox=new int[len];
- double time=0;
+ double time_encrypt=0;
+ double time_decrypt=0;
+
+
double t=TimeStart();
rc4key(DK, Sbox1, 8);
rc4keyperm(&DK[48], h2, rp, PboxRM, 16);
- time+=TimeStop(t);
- cout<<"Time initializaton "<<time<<endl;
+ //time+=TimeStop(t);
+ //cout<<"Time initializaton "<<time<<endl;
- time=0;
+ time_encrypt=0;
t=TimeStart();
int i;
}
break;
}
- time+=TimeStop(t);
- cout<<"Time encrypt "<<time<<endl;
+ time_encrypt+=TimeStop(t);
+ //cout<<"Time encrypt "<<
+ cout<<(double)imsize*nb_test/time_encrypt<<"\t";
if(lena) {
}
- time=0;
+ time_decrypt=0;
t=TimeStart();
switch(h) {
case 4:
break;
}
- time+=TimeStop(t);
- cout<<"Time decrypt "<<time<<endl;
+ time_decrypt+=TimeStop(t);
+ //cout<<"Time decrypt "
+ cout<<(double)imsize*nb_test/time_decrypt<<"\t";
if(lena) {
for(int i=0;i<oneD;i++) {