#include<string.h>
#include <fstream>
#include <sys/time.h>
+#include <glib.h>
+
/*#include <cryptopp/hex.h>
#include <cryptopp/sha.h>
uchar j0=0;
for (int it=0; it<ldata; it++) {
- i0 = ((i0+1)&0xFE); //%255);
+ i0 = ((i0+1)%255);
j0 = (j0 + sc[i0])&0xFF;
uchar tmp = sc[i0];
sc[i0] = sc[j0];
}
}
+inline uchar circ(uchar x,int n) {return (x << n) | (x >> (8 - n));}
void diff(uchar *Y, uchar *X, int h) {
Y[3] = X[0]^X[1]^X[2];
}
else if(h==8) {
- Y[0] = X[0]^X[2]^X[3]^X[5]^X[6]^X[7];
+ /*Y[0] = X[0]^X[2]^X[3]^X[5]^X[6]^X[7];
Y[1] = X[0]^X[1]^X[3]^X[4]^X[6]^X[7];
Y[2] = X[0]^X[1]^X[2]^X[4]^X[5]^X[7];
Y[3] = X[1]^X[2]^X[3]^X[4]^X[5]^X[6];
Y[5] = X[1]^X[2]^X[4]^X[6]^X[7];
Y[6] = X[2]^X[3]^X[4]^X[5]^X[7];
Y[7] = X[0]^X[3]^X[4]^X[5]^X[6];
+ */
+
+
+ uchar X0=X[0];
+ uchar X1=X[1];
+ uchar X2=X[2];
+ uchar X3=X[3];
+ uchar X4=X[4];
+ uchar X5=X[5];
+ uchar X6=X[6];
+ uchar X7=X[7];
+
+ Y[0] = X0^X2^X3^X5^X6^X7;
+ Y[1] = X0^X1^X3^X4^X6^X7;
+ Y[2] = X0^X1^X2^X4^X5^X7;
+ Y[3] = X1^X2^X3^X4^X5^X6;
+ Y[4] = X0^X1^X5^X6^X7;
+ Y[5] = X1^X2^X4^X6^X7;
+ Y[6] = X2^X3^X4^X5^X7;
+ Y[7] = X0^X3^X4^X5^X6;
+
+
}
else if(h==16) {
-
- Y[0] = X[3] ^ X[4] ^ X[6] ^ X[8] ^ X[9] ^ X[13] ^ X[14];
+ /*
+ Y[0] = X[3] ^ X[4] ^ X[6] ^ X[8] ^ X[9] ^ X[13] ^ X[14];
Y[1] = X[2] ^ X[5] ^ X[7] ^ X[8] ^ X[9] ^ X[12] ^ X[15];
Y[2] = X[1] ^ X[4] ^ X[6] ^ X[10] ^ X[11] ^ X[12] ^ X[15];
Y[3] = X[0] ^ X[5] ^ X[7] ^ X[10] ^ X[11] ^ X[13] ^ X[14];
Y[12] = X[1] ^ X[2] ^ X[6] ^ X[7] ^ X[9] ^ X[11] ^ X[12];
Y[13] = X[0] ^ X[3] ^ X[6] ^ X[7] ^ X[8] ^ X[10] ^ X[13];
Y[14] = X[0] ^ X[3] ^ X[4] ^ X[5] ^ X[9] ^ X[11] ^ X[14];
- Y[15] = X[1] ^ X[2] ^ X[4] ^ X[5] ^ X[8] ^ X[10] ^ X[15];
+ Y[15] = X[1] ^ X[2] ^ X[4] ^ X[5] ^ X[8] ^ X[10] ^ X[15];
+ */
+
+ uchar X0=X[0];
+ uchar X1=X[1];
+ uchar X2=X[2];
+ uchar X3=X[3];
+ uchar X4=X[4];
+ uchar X5=X[5];
+ uchar X6=X[6];
+ uchar X7=X[7];
+ uchar X8=X[8];
+ uchar X9=X[9];
+ uchar X10=X[10];
+ uchar X11=X[11];
+ uchar X12=X[12];
+ uchar X13=X[13];
+ uchar X14=X[14];
+ uchar X15=X[15];
+
+
+ Y[0] = X3 ^ X4 ^ X6 ^ X8 ^ X9 ^ X13 ^ X14;
+ Y[1] = X2 ^ X5 ^ X7 ^ X8 ^ X9 ^ X12 ^ X15;
+ Y[2] = X1 ^ X4 ^ X6 ^ X10 ^ X11 ^ X12 ^ X15;
+ Y[3] = X0 ^ X5 ^ X7 ^ X10 ^ X11 ^ X13 ^ X14;
+ Y[4] = X0 ^ X2 ^ X5 ^ X8 ^ X11 ^ X14 ^ X15;
+ Y[5] = X1 ^ X3 ^ X4 ^ X9 ^ X10 ^ X14 ^ X15;
+ Y[6] = X0 ^ X2 ^ X7 ^ X9 ^ X10 ^ X12 ^ X13;
+ Y[7] = X1 ^ X3 ^ X6 ^ X8 ^ X11 ^ X12 ^ X13;
+ Y[8] = X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ar X5=X[5];
+ uchar X6=X[6];
+ uchar X7=X[7];
+ uchar X8=X[8];
+ uchar X9=X[9];
+ uchar X10=X[10];
+ uchar X11=X[11];
+ uchar X12=X[12];
+ uchar X13=X[13];
+ uchar X14=X[14];
+ uchar X15=X[15];
+ uchar X16=X[16];
+ uchar X17=X[17];
+ uchar X18=X[18];
+ uchar X19=X[19];
+ uchar X20=X[20];
+ uchar X21=X[21];
+ uchar X22=X[22];
+ uchar X23=X[23];
+ uchar X24=X[24];
+ uchar X25=X[25];
+ uchar X26=X[26];
+ uchar X27=X[27];
+ uchar X28=X[28];
+ uchar X29=X[29];
+ uchar X30=X[30];
+ uchar X31=X[31];
+
+ Y[0]=X0^X1^X2^X3^X4^X7^X8^X10^X12^X15^X16^X17^X18^X20^X21^X24^X25^X28^X30;
+ Y[1]=X0^ X1^X2^X3^X5^X6^X9^X11^X13^X14^X16^X17^X19^X20^X21^ X24^X25^X29^X31;
+ Y[2]=X0^X1^X2^X3^X5^X6^X8^X10^X13^X14^X16^X18^X19^X22^X23^X26^X27^X28^X30;
+ Y[3]=X0^X1^X2^X3^X4^X7^X9^X11^X12^X15^X17^X18^X19^X22^X23^X26^X27^X29^X31;
+ Y[4]=X0^X3^X5^X6^X7^X10^X11^ X12^X13^X14^ X15^X16^X19^X21^X23^ X25^X27^X30^X31;
+ Y[5]=X1^X2^X4^X6^X7^X10^X11^X12^X13^X14^X16 ^X17^X18^X20^X22^X24^X26^X30^X31;
+ Y[6]=X1^X2^X4^X5^X7^X8^X9^X12^X13^X14^X15^ X17^X18^X21^X23^X25^X27^X28^X29;
+ Y[7]=X0^X3^X4^X5^X6^X9 ^X9^X12^X13^X14^X15^X16^X19^X20^X22^X24^X26^X28^X29;
+ Y[8]=X0^X2^X6^X7^X8^X10^X11^X14^X15^X16^X18^X21^X22^X25^X26;
+ Y[9]=X1^ X3^X6^X7^X9^X10^X11^X14^X15^X17^X19^X20^X23^X24^X27;
+ Y[10]=X0^X2^X4^X5^X8^X9^X10^X12^X13^X16^X18^X20^X23^ X24^X27;
+ Y[11]=X1^X3^X4^X5^X8^X9^X11^X12^X13^X17^X19^X21^X22^X25^X26;
+ Y[12]=X0^X3^X4^X5^X6^X7^X10^X11^X13^X14^X15^X16^X19^X21^X23^X25^X27^X30^X31;
+ Y[13]=X1^X2^X4^X5^X6^X7^X10^X11^X12^X14^X15^X17^ X18^X20^X22^X24^X26^X30^X31;
+ Y[14]=X1^X2^X4^X5^X6^X7^X8^X9^X12^X13^X15^X17^X18^X21^X23^X25^X27^X28^X29;
+ Y[15]=X0^X3^X4^X5^X6^X7^X8^X9^X12^X13^X14^X16^X19^X20^X22^ X24^X26^X28^X29;
+ Y[16]=X0^X1^X2^X4^X8 ^X8^X10^X13 ^X15^X16^X17^X18^X19^X20^X21^X24^X25^X28^X30;
+ Y[17]=X0^X1^X3^X5^X6^X9^X11^X13^X14^X16^X17^X18^X19^X20^X21^X24^X25^X29^X31;
+ Y[18]=X0^X2^X3^X5^X6^X8^X10^X13^X14^X16^X17^X18^X19^X22^X23^X26^X27^X28^X30;
+ Y[19]=X1^X2^X3^X4^X7^X9^X11^X12^X15^X16^X17^X18^X19^X22^X23^X26^X28 ^X29^X31;
+ Y[20]=X0^X1^X5^X7^X10 ^X10^X13^X15^X16^X17^X20^X21^X23^X29^X30;
+ Y[21]=X0^X1^X4^X6^X8^X11^X12^X14^X16^X17^X20^X21^X22^X28^X31;
+ Y[22]=X2^X3^X5^X7^X8^X11^X13^X15^X18^X19^X21^X22^X23^X28^X31;
+ Y[23]=X2^X3^X4^X6^X9^X10^X12^X14^ X18^X19^X20^X22^X23^X29^X30;
+ Y[24]=X0^X1^X5^X7^X9^X10^X13^X15^X16^X17^X24^X25^X27^X29^X30;
+ Y[25]=X0^X1^X4^X6^X8^X11^X12^X14^X16^X17^X24^X25^X26^X28^X31;
+ Y[26]=X2^X3^X5^X7^X8^X11^X13^X15^X18^X19^X25^X26^X27^X28^ X31;
+ Y[27]=X2^X3^X4^X6^X9^X10^X12^X14^X18^X19^X24^X26^X27^X29^X30;
+ Y[28]=X0^X2^X6^X7^X14^X15^X16^X18^X21^X22^X25^X26^X28^X30^X31;
+ Y[29]=X2^X3^X6^X7^X14^X15^X17^X19^X20^X23^X24^X27^X29^X30^X31;
+ Y[30]=X1^X2^X4^X5^X12^X13^X16^X18^X20^X23^X24^X27^X28^X29^X30;
+ Y[31]=X2^X3^X4^X5^X12^X13^X17^X19^X21^X22^X25^X26^X28^X29^X31;
+
+
}
}
}
// Second Diffusion Operation
+
+ /*for(int a=0;a<h;a+=4) {
+ fX2[a]=circ(X[a],3);
+ fX2[a+1]=circ(X[a+1],5);
+ fX2[a+2]=circ(X[a+2],1);
+ fX2[a+3]=circ(X[a+3],6);
+ }*/
diff(fX2,fX,h);
RM1[a+1]=fX2[a+1]^RM1[PboxRM[a+1]];
RM1[a+2]=fX2[a+2]^RM1[PboxRM[a+2]];
RM1[a+3]=fX2[a+3]^RM1[PboxRM[a+3]];
+ }
+/*
+ for(int a=0;a<h;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]];
}
+
+ for(int a=0;a<h;a+=4) {
+ RM1[a]=fX2[a]^RM1[a];
+ RM1[a+1]=fX2[a+1]^RM1[a+1];
+ RM1[a+2]=fX2[a+2]^RM1[a+2];
+ RM1[a+3]=fX2[a+3]^RM1[a+3];
+ }
+*/
+
+
}
seq[4]++;
}
-
+ if(change==2) {
+
+ seq[9]++;
+ }
time+=TimeStop(t);
cout<<"Hash Time "<<time<<endl;
-
+ cout<<(double)imsize*nb_test/time<<"\t";
for(int i=0;i<h;i++){
cout<<(int)RM1[i]<<" ";