2 //g++ -O3 one_round_new.cpp pixmap_io.o -o one_round_new -std=c++11
15 /*#include <cryptopp/hex.h>
16 #include <cryptopp/sha.h>
17 #include <cryptopp/osrng.h>
18 #include <cryptopp/secblock.h>
23 int load_RGB_pixmap(char *filename, int *width, int *height, unsigned char**R_data, unsigned char**G_data, unsigned char**B_data);
24 void store_RGB_pixmap(char *filename, unsigned char *R_data, unsigned char *G_data, unsigned char *B_data, int width, int height);
28 //using namespace CryptoPP;
41 typedef __uint64_t mylong;
44 typedef unsigned char uchar;
49 struct timeval tstart;
50 gettimeofday(&tstart,0);
51 return( (double) (tstart.tv_sec + tstart.tv_usec*1e-6) );
54 double TimeStop(double t)
58 gettimeofday(&tend,0);
59 t = (double) (tend.tv_sec + tend.tv_usec*1e-6) - t;
66 uint xorshift32(const uint t)
68 /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
81 /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
92 __uint128_t g_lehmer64_state;
94 inline uint64_t splitmix64_stateless(uint64_t index) {
95 uint64_t z = (index + UINT64_C(0x9E3779B97F4A7C15));
96 z = (z ^ (z >> 30)) * UINT64_C(0xBF58476D1CE4E5B9);
97 z = (z ^ (z >> 27)) * UINT64_C(0x94D049BB133111EB);
102 inline void lehmer64_seed(uint64_t seed) {
103 g_lehmer64_state = (((__uint128_t)splitmix64_stateless(seed)) << 64) +
104 splitmix64_stateless(seed + 1);
107 inline uint64_t lehmer64() {
108 g_lehmer64_state *= UINT64_C(0xda942042e4dd58b5);
110 return g_lehmer64_state >> 64;
117 void inverse_tables(uchar *tab, int size_tab,uchar *inv_perm_tabs) {
119 for(int i=0;i<size_tab;i++) {
120 inv_perm_tabs[tab[i]] = i;
125 void inverse_tables_int(int *tab, int size_tab,int *inv_perm_tabs) {
127 for(int i=0;i<size_tab;i++) {
128 inv_perm_tabs[tab[i]] = i;
135 void rc4key(uchar *key, uchar *sc, int size_DK) {
137 for(int i=0;i<256;i++) {
143 for(int i0=0; i0<256; i0++) {
144 j0 = (j0 + sc[i0] + key[i0%size_DK] )&0xFF;
153 void rc4keyperm(uchar *key,int len, int rp,int *sc, int size_DK) {
159 for (int i=0;i<len;i++) {
162 for (int it = 0; it < rp; it++) {
164 for(int i0 = 0; i0<len; i0++) {
165 j0 = (j0 + sc[i0] + sc[j0] + key[i0%size_DK] )% len;
174 void prga(uchar *sc, int ldata, uchar *r) {
178 for (int it=0; it<ldata; it++) {
180 j0 = (j0 + sc[i0])&0xFF;
184 r[it]=sc[(sc[i0]+sc[j0])&0xFF];
194 void encrypt_ecb_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar* IV,mylong myrand, int debug) {
203 mylong *rm1=(mylong*)RM1;
204 mylong *rm2=(mylong*)RM2;
208 for(int it=0;it<len/2;it++) {
210 int ind2=Pbox[it+len/2]*h;
213 for(int a=0;a<(h>>3);a++) {
222 for(int a=0;a<h;a+=4) {
224 X[a+1]=seq_in[ind2+a+1];
225 X[a+2]=seq_in[ind2+a+2];
226 X[a+3]=seq_in[ind2+a+3];
229 for(int a=0;a<h;a+=4) {
231 Y[a+1]=seq_in[ind1+a+1];
232 Y[a+2]=seq_in[ind1+a+2];
233 Y[a+3]=seq_in[ind1+a+3];
237 for(int a=0;a<h;a+=4) {
238 tmp[a]=Sbox1[X[a]^RM1[a]];
239 tmp[a+1]=Sbox1[X[a+1]^RM1[a+1]];
240 tmp[a+2]=Sbox1[X[a+2]^RM1[a+2]];
241 tmp[a+3]=Sbox1[X[a+3]^RM1[a+3]];
244 for(int a=0;a<h;a+=4) {
245 fX[a]=Sbox2[tmp[a]^Y[a]];
246 fX[a+1]=Sbox2[tmp[a+1]^Y[a+1]];
247 fX[a+2]=Sbox2[tmp[a+2]^Y[a+2]];
248 fX[a+3]=Sbox2[tmp[a+3]^Y[a+3]];
252 /*for(int a=0;a<h;a+=4) {
253 fX[a]=Sbox2[Sbox1[X[a]^RM1[a]]^Y[a]];
254 fX[a+1]=Sbox2[Sbox1[X[a+1]^RM1[a+1]]^Y[a+1]];
255 fX[a+2]=Sbox2[Sbox1[X[a+2]^RM1[a+2]]^Y[a+2]];
256 fX[a+3]=Sbox2[Sbox1[X[a+3]^RM1[a+3]]^Y[a+3]];
262 for(int a=0;a<h;a+=4) {
263 tmp[a]=Sbox2[fX[a]^Y[a]];
264 tmp[a+1]=Sbox2[fX[a+1]^Y[a+1]];
265 tmp[a+2]=Sbox2[fX[a+2]^Y[a+2]];
266 tmp[a+3]=Sbox2[fX[a+3]^Y[a+3]];
269 for(int a=0;a<h;a+=4) {
270 gY[a]=Sbox1[tmp[a]^RM2[a]];
271 gY[a+1]=Sbox1[tmp[a+1]^RM2[a+1]];
272 gY[a+2]=Sbox1[tmp[a+2]^RM2[a+2]];
273 gY[a+3]=Sbox1[tmp[a+3]^RM2[a+3]];
278 /* for(int a=0;a<h;a+=4) {
279 gY[a]=Sbox1[Sbox2[fX[a]^Y[a]]^RM2[a]];
280 gY[a+1]=Sbox1[Sbox2[fX[a+1]^Y[a+1]]^RM2[a+1]];
281 gY[a+2]=Sbox1[Sbox2[fX[a+2]^Y[a+2]]^RM2[a+2]];
282 gY[a+3]=Sbox1[Sbox2[fX[a+3]^Y[a+3]]^RM2[a+3]];
291 for(int a=0;a<h;a+=4) {
292 seq_out[ind2+a]=gY[a];
293 seq_out[ind2+a+1]=gY[a+1];
294 seq_out[ind2+a+2]=gY[a+2];
295 seq_out[ind2+a+3]=gY[a+3];
298 for(int a=0;a<h;a+=4) {
299 seq_out[ind1+a]=fX[a];
300 seq_out[ind1+a+1]=fX[a+1];
301 seq_out[ind1+a+2]=fX[a+2];
302 seq_out[ind1+a+3]=fX[a+3];
322 void decrypt_ecb_prng(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2, uchar* IV,mylong myrand, int debug) {
331 mylong *rm1=(mylong*)RM1;
332 mylong *rm2=(mylong*)RM2;
335 for(int it=0;it<len/2;it++) {
337 int ind2=Pbox[it+len/2]*h;
340 for(int a=0;a<(h>>3);a++) {
349 for(int a=0;a<h;a+=4) {
350 gY[a]=seq_in[ind2+a];
351 gY[a+1]=seq_in[ind2+a+1];
352 gY[a+2]=seq_in[ind2+a+2];
353 gY[a+3]=seq_in[ind2+a+3];
356 for(int a=0;a<h;a+=4) {
357 fX[a]=seq_in[ind1+a];
358 fX[a+1]=seq_in[ind1+a+1];
359 fX[a+2]=seq_in[ind1+a+2];
360 fX[a+3]=seq_in[ind1+a+3];
366 for(int a=0;a<h;a+=4) {
367 tmp[a]=Inv_Sbox1[gY[a]]^RM2[a];
368 tmp[a+1]=Inv_Sbox1[gY[a+1]]^RM2[a+1];
369 tmp[a+2]=Inv_Sbox1[gY[a+2]]^RM2[a+2];
370 tmp[a+3]=Inv_Sbox1[gY[a+3]]^RM2[a+3];
374 for(int a=0;a<h;a+=4) {
375 invgY[a]=Inv_Sbox2[tmp[a]]^fX[a];
376 invgY[a+1]=Inv_Sbox2[tmp[a+1]]^fX[a+1];
377 invgY[a+2]=Inv_Sbox2[tmp[a+2]]^fX[a+2];
378 invgY[a+3]=Inv_Sbox2[tmp[a+3]]^fX[a+3];
383 /* for(int a=0;a<h;a+=4) {
384 invgY[a]=Inv_Sbox2[Inv_Sbox1[gY[a]]^RM2[a]]^fX[a];
385 invgY[a+1]=Inv_Sbox2[Inv_Sbox1[gY[a+1]]^RM2[a+1]]^fX[a+1];
386 invgY[a+2]=Inv_Sbox2[Inv_Sbox1[gY[a+2]]^RM2[a+2]]^fX[a+2];
387 invgY[a+3]=Inv_Sbox2[Inv_Sbox1[gY[a+3]]^RM2[a+3]]^fX[a+3];
393 for(int a=0;a<h;a+=4) {
394 tmp[a]=Inv_Sbox2[fX[a]]^invgY[a];
395 tmp[a+1]=Inv_Sbox2[fX[a+1]]^invgY[a+1];
396 tmp[a+2]=Inv_Sbox2[fX[a+2]]^invgY[a+2];
397 tmp[a+3]=Inv_Sbox2[fX[a+3]]^invgY[a+3];
401 for(int a=0;a<h;a+=4) {
402 invfX[a]=Inv_Sbox1[tmp[a]]^RM1[a];
403 invfX[a+1]=Inv_Sbox1[tmp[a+1]]^RM1[a+1];
404 invfX[a+2]=Inv_Sbox1[tmp[a+2]]^RM1[a+2];
405 invfX[a+3]=Inv_Sbox1[tmp[a+3]]^RM1[a+3];
411 for(int a=0;a<h;a+=4) {
412 invfX[a]=Inv_Sbox1[Inv_Sbox2[fX[a]]^invgY[a]]^RM1[a];
413 invfX[a+1]=Inv_Sbox1[Inv_Sbox2[fX[a+1]]^invgY[a+1]]^RM1[a+1];
414 invfX[a+2]=Inv_Sbox1[Inv_Sbox2[fX[a+2]]^invgY[a+2]]^RM1[a+2];
415 invfX[a+3]=Inv_Sbox1[Inv_Sbox2[fX[a+3]]^invgY[a+3]]^RM1[a+3];
420 for(int a=0;a<h;a+=4) {
421 seq_out[ind2+a]=invfX[a];
422 seq_out[ind2+a+1]=invfX[a+1];
423 seq_out[ind2+a+2]=invfX[a+2];
424 seq_out[ind2+a+3]=invfX[a+3];
427 for(int a=0;a<h;a+=4) {
428 seq_out[ind1+a]=invgY[a];
429 seq_out[ind1+a+1]=invgY[a+1];
430 seq_out[ind1+a+2]=invgY[a+2];
431 seq_out[ind1+a+3]=invgY[a+3];
449 void encrypt_ecb_rm(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *IV, int debug) {
463 for(int a=0;a<h;a+=4) {
471 for(int a=0;a<h;a+=4) {
484 for(int it=0;it<len/2;it++) {
486 int ind2=Pbox[it+len/2]*h;
489 RM1=&RM[PboxSRM[it]*h];
490 RM2=&RM[h*h+PboxSRM[len/2-it-1]*h];
494 for(int a=0;a<h;a+=4) {
496 X[a+1]=seq_in[ind2+a+1];
497 X[a+2]=seq_in[ind2+a+2];
498 X[a+3]=seq_in[ind2+a+3];
501 for(int a=0;a<h;a+=4) {
503 Y[a+1]=seq_in[ind1+a+1];
504 Y[a+2]=seq_in[ind1+a+2];
505 Y[a+3]=seq_in[ind1+a+3];
509 for(int a=0;a<h;a+=4) {
510 tmp[a]=Sbox1[X[a]^RM1[a]];
511 tmp[a+1]=Sbox1[X[a+1]^RM1[a+1]];
512 tmp[a+2]=Sbox1[X[a+2]^RM1[a+2]];
513 tmp[a+3]=Sbox1[X[a+3]^RM1[a+3]];
516 for(int a=0;a<h;a+=4) {
517 fX[a]=Sbox2[tmp[a]^Y[a]];
518 fX[a+1]=Sbox2[tmp[a+1]^Y[a+1]];
519 fX[a+2]=Sbox2[tmp[a+2]^Y[a+2]];
520 fX[a+3]=Sbox2[tmp[a+3]^Y[a+3]];
524 /*for(int a=0;a<h;a+=4) {
525 fX[a]=Sbox2[Sbox1[X[a]^RM1[a]]^Y[a]];
526 fX[a+1]=Sbox2[Sbox1[X[a+1]^RM1[a+1]]^Y[a+1]];
527 fX[a+2]=Sbox2[Sbox1[X[a+2]^RM1[a+2]]^Y[a+2]];
528 fX[a+3]=Sbox2[Sbox1[X[a+3]^RM1[a+3]]^Y[a+3]];
534 for(int a=0;a<h;a+=4) {
535 tmp[a]=Sbox2[fX[a]^Y[a]];
536 tmp[a+1]=Sbox2[fX[a+1]^Y[a+1]];
537 tmp[a+2]=Sbox2[fX[a+2]^Y[a+2]];
538 tmp[a+3]=Sbox2[fX[a+3]^Y[a+3]];
541 for(int a=0;a<h;a+=4) {
542 gY[a]=Sbox1[tmp[a]^RM2[a]];
543 gY[a+1]=Sbox1[tmp[a+1]^RM2[a+1]];
544 gY[a+2]=Sbox1[tmp[a+2]^RM2[a+2]];
545 gY[a+3]=Sbox1[tmp[a+3]^RM2[a+3]];
550 /* for(int a=0;a<h;a+=4) {
551 gY[a]=Sbox1[Sbox2[fX[a]^Y[a]]^RM2[a]];
552 gY[a+1]=Sbox1[Sbox2[fX[a+1]^Y[a+1]]^RM2[a+1]];
553 gY[a+2]=Sbox1[Sbox2[fX[a+2]^Y[a+2]]^RM2[a+2]];
554 gY[a+3]=Sbox1[Sbox2[fX[a+3]^Y[a+3]]^RM2[a+3]];
563 for(int a=0;a<h;a+=4) {
564 seq_out[ind2+a]=gY[a];
565 seq_out[ind2+a+1]=gY[a+1];
566 seq_out[ind2+a+2]=gY[a+2];
567 seq_out[ind2+a+3]=gY[a+3];
570 for(int a=0;a<h;a+=4) {
571 seq_out[ind1+a]=fX[a];
572 seq_out[ind1+a+1]=fX[a+1];
573 seq_out[ind1+a+2]=fX[a+2];
574 seq_out[ind1+a+3]=fX[a+3];
594 void decrypt_ecb_rm(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2, uchar *IV, int debug) {
608 for(int a=0;a<h;a+=4) {
616 for(int a=0;a<h;a+=4) {
626 for(int it=0;it<len/2;it++) {
628 int ind2=Pbox[it+len/2]*h;
631 RM1=&RM[PboxSRM[it]*h];
632 RM2=&RM[h*h+PboxSRM[len/2-it-1]*h];
636 for(int a=0;a<h;a+=4) {
637 gY[a]=seq_in[ind2+a];
638 gY[a+1]=seq_in[ind2+a+1];
639 gY[a+2]=seq_in[ind2+a+2];
640 gY[a+3]=seq_in[ind2+a+3];
643 for(int a=0;a<h;a+=4) {
644 fX[a]=seq_in[ind1+a];
645 fX[a+1]=seq_in[ind1+a+1];
646 fX[a+2]=seq_in[ind1+a+2];
647 fX[a+3]=seq_in[ind1+a+3];
653 for(int a=0;a<h;a+=4) {
654 tmp[a]=Inv_Sbox1[gY[a]]^RM2[a];
655 tmp[a+1]=Inv_Sbox1[gY[a+1]]^RM2[a+1];
656 tmp[a+2]=Inv_Sbox1[gY[a+2]]^RM2[a+2];
657 tmp[a+3]=Inv_Sbox1[gY[a+3]]^RM2[a+3];
661 for(int a=0;a<h;a+=4) {
662 invgY[a]=Inv_Sbox2[tmp[a]]^fX[a];
663 invgY[a+1]=Inv_Sbox2[tmp[a+1]]^fX[a+1];
664 invgY[a+2]=Inv_Sbox2[tmp[a+2]]^fX[a+2];
665 invgY[a+3]=Inv_Sbox2[tmp[a+3]]^fX[a+3];
670 /* for(int a=0;a<h;a+=4) {
671 invgY[a]=Inv_Sbox2[Inv_Sbox1[gY[a]]^RM2[a]]^fX[a];
672 invgY[a+1]=Inv_Sbox2[Inv_Sbox1[gY[a+1]]^RM2[a+1]]^fX[a+1];
673 invgY[a+2]=Inv_Sbox2[Inv_Sbox1[gY[a+2]]^RM2[a+2]]^fX[a+2];
674 invgY[a+3]=Inv_Sbox2[Inv_Sbox1[gY[a+3]]^RM2[a+3]]^fX[a+3];
680 for(int a=0;a<h;a+=4) {
681 tmp[a]=Inv_Sbox2[fX[a]]^invgY[a];
682 tmp[a+1]=Inv_Sbox2[fX[a+1]]^invgY[a+1];
683 tmp[a+2]=Inv_Sbox2[fX[a+2]]^invgY[a+2];
684 tmp[a+3]=Inv_Sbox2[fX[a+3]]^invgY[a+3];
688 for(int a=0;a<h;a+=4) {
689 invfX[a]=Inv_Sbox1[tmp[a]]^RM1[a];
690 invfX[a+1]=Inv_Sbox1[tmp[a+1]]^RM1[a+1];
691 invfX[a+2]=Inv_Sbox1[tmp[a+2]]^RM1[a+2];
692 invfX[a+3]=Inv_Sbox1[tmp[a+3]]^RM1[a+3];
698 for(int a=0;a<h;a+=4) {
699 invfX[a]=Inv_Sbox1[Inv_Sbox2[fX[a]]^invgY[a]]^RM1[a];
700 invfX[a+1]=Inv_Sbox1[Inv_Sbox2[fX[a+1]]^invgY[a+1]]^RM1[a+1];
701 invfX[a+2]=Inv_Sbox1[Inv_Sbox2[fX[a+2]]^invgY[a+2]]^RM1[a+2];
702 invfX[a+3]=Inv_Sbox1[Inv_Sbox2[fX[a+3]]^invgY[a+3]]^RM1[a+3];
707 for(int a=0;a<h;a+=4) {
708 seq_out[ind2+a]=invfX[a];
709 seq_out[ind2+a+1]=invfX[a+1];
710 seq_out[ind2+a+2]=invfX[a+2];
711 seq_out[ind2+a+3]=invfX[a+3];
714 for(int a=0;a<h;a+=4) {
715 seq_out[ind1+a]=invgY[a];
716 seq_out[ind1+a+1]=invgY[a+1];
717 seq_out[ind1+a+2]=invgY[a+2];
718 seq_out[ind1+a+3]=invgY[a+3];
739 void encrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *IV,uint myrand, int debug) {
750 mylong *rm1=(mylong*)RM1;
751 mylong *rm2=(mylong*)RM2;
755 for(int a=0;a<h;a+=4) {
763 for(int a=0;a<h;a+=4) {
772 for(int it=0;it<len/2;it++) {
774 int ind2=Pbox[it+len/2]*h;
777 for(int a=0;a<(h>>3);a++) {
786 for(int a=0;a<h;a+=4) {
788 X[a+1]=seq_in[ind2+a+1];
789 X[a+2]=seq_in[ind2+a+2];
790 X[a+3]=seq_in[ind2+a+3];
793 for(int a=0;a<h;a+=4) {
795 Y[a+1]=seq_in[ind1+a+1];
796 Y[a+2]=seq_in[ind1+a+2];
797 Y[a+3]=seq_in[ind1+a+3];
801 for(int a=0;a<h;a+=4) {
802 tmp[a]=X[a]^RM1[a]^IV1[a];
803 tmp[a+1]=X[a+1]^RM1[a+1]^IV1[a+1];
804 tmp[a+2]=X[a+2]^RM1[a+2]^IV1[a+2];
805 tmp[a+3]=X[a+3]^RM1[a+3]^IV1[a+3];
808 for(int a=0;a<h;a+=4) {
809 tmp[a]=Sbox1[tmp[a]];
810 tmp[a+1]=Sbox1[tmp[a+1]];
811 tmp[a+2]=Sbox1[tmp[a+2]];
812 tmp[a+3]=Sbox1[tmp[a+3]];
816 /* for(int a=0;a<h;a+=4) {
817 tmp[a]=Sbox1[X[a]^RM1[a]^IV1[a]];
818 tmp[a+1]=Sbox1[X[a+1]^RM1[a+1]^IV1[a+1]];
819 tmp[a+2]=Sbox1[X[a+2]^RM1[a+2]^IV1[a+2]];
820 tmp[a+3]=Sbox1[X[a+3]^RM1[a+3]^IV1[a+3]];
823 for(int a=0;a<h;a+=4) {
824 fX[a]=Sbox2[tmp[a]^Y[a]];
825 fX[a+1]=Sbox2[tmp[a+1]^Y[a+1]];
826 fX[a+2]=Sbox2[tmp[a+2]^Y[a+2]];
827 fX[a+3]=Sbox2[tmp[a+3]^Y[a+3]];
831 /*for(int a=0;a<h;a+=4) {
832 fX[a]=Sbox2[Sbox1[X[a]^RM1[a]^IV1[a]]^Y[a]];
833 fX[a+1]=Sbox2[Sbox1[X[a+1]^RM1[a+1]^IV1[a+1]]^Y[a+1]];
834 fX[a+2]=Sbox2[Sbox1[X[a+2]^RM1[a+2]^IV1[a+2]]^Y[a+2]];
835 fX[a+3]=Sbox2[Sbox1[X[a+3]^RM1[a+3]^IV1[a+3]]^Y[a+3]];
839 for(int a=0;a<h;a+=4) {
840 tmp[a]=fX[a]^Y[a]^IV2[a];
841 tmp[a+1]=fX[a+1]^Y[a+1]^IV2[a+1];
842 tmp[a+2]=fX[a+2]^Y[a+2]^IV2[a+2];
843 tmp[a+3]=fX[a+3]^Y[a+3]^IV2[a+3];
847 for(int a=0;a<h;a+=4) {
848 tmp[a]=Sbox2[tmp[a]];
849 tmp[a+1]=Sbox2[tmp[a+1]];
850 tmp[a+2]=Sbox2[tmp[a+2]];
851 tmp[a+3]=Sbox2[tmp[a+3]];
856 for(int a=0;a<h;a+=4) {
857 tmp[a]=Sbox2[fX[a]^Y[a]^IV2[a]];
858 tmp[a+1]=Sbox2[fX[a+1]^Y[a+1]^IV2[a+1]];
859 tmp[a+2]=Sbox2[fX[a+2]^Y[a+2]^IV2[a+2]];
860 tmp[a+3]=Sbox2[fX[a+3]^Y[a+3]^IV2[a+3]];
865 for(int a=0;a<h;a+=4) {
866 gY[a]=Sbox1[tmp[a]^RM2[a]];
867 gY[a+1]=Sbox1[tmp[a+1]^RM2[a+1]];
868 gY[a+2]=Sbox1[tmp[a+2]^RM2[a+2]];
869 gY[a+3]=Sbox1[tmp[a+3]^RM2[a+3]];
876 for(int a=0;a<h;a+=4) {
877 gY[a]=Sbox1[Sbox2[fX[a]^Y[a]^IV2[a]]^RM2[a]];
878 gY[a+1]=Sbox1[Sbox2[fX[a+1]^Y[a+1]^IV2[a+1]]^RM2[a+1]];
879 gY[a+2]=Sbox1[Sbox2[fX[a+2]^Y[a+2]^IV2[a+2]]^RM2[a+2]];
880 gY[a+3]=Sbox1[Sbox2[fX[a+3]^Y[a+3]^IV2[a+3]]^RM2[a+3]];
885 for(int a=0;a<h;a+=4) {
886 seq_out[ind2+a]=gY[a];
887 seq_out[ind2+a+1]=gY[a+1];
888 seq_out[ind2+a+2]=gY[a+2];
889 seq_out[ind2+a+3]=gY[a+3];
892 for(int a=0;a<h;a+=4) {
893 seq_out[ind1+a]=fX[a];
894 seq_out[ind1+a+1]=fX[a+1];
895 seq_out[ind1+a+2]=fX[a+2];
896 seq_out[ind1+a+3]=fX[a+3];
898 for(int a=0;a<h;a+=4) {
905 for(int a=0;a<h;a+=4) {
927 void decrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2, uchar* IV, uint myrand, int debug) {
938 mylong *rm1=(mylong*)RM1;
939 mylong *rm2=(mylong*)RM2;
943 for(int a=0;a<h;a+=4) {
951 for(int a=0;a<h;a+=4) {
960 for(int it=0;it<len/2;it++) {
962 int ind2=Pbox[it+len/2]*h;
965 for(int a=0;a<(h>>3);a++) {
972 for(int a=0;a<h;a+=4) {
973 gY[a]=seq_in[ind2+a];
974 gY[a+1]=seq_in[ind2+a+1];
975 gY[a+2]=seq_in[ind2+a+2];
976 gY[a+3]=seq_in[ind2+a+3];
979 for(int a=0;a<h;a+=4) {
980 fX[a]=seq_in[ind1+a];
981 fX[a+1]=seq_in[ind1+a+1];
982 fX[a+2]=seq_in[ind1+a+2];
983 fX[a+3]=seq_in[ind1+a+3];
987 for(int a=0;a<h;a+=4) {
988 tmp[a]=Inv_Sbox1[gY[a]]^RM2[a];
989 tmp[a+1]=Inv_Sbox1[gY[a+1]]^RM2[a+1];
990 tmp[a+2]=Inv_Sbox1[gY[a+2]]^RM2[a+2];
991 tmp[a+3]=Inv_Sbox1[gY[a+3]]^RM2[a+3];
995 for(int a=0;a<h;a+=4) {
996 tmp[a]=Inv_Sbox2[tmp[a]];
997 tmp[a+1]=Inv_Sbox2[tmp[a+1]];
998 tmp[a+2]=Inv_Sbox2[tmp[a+2]];
999 tmp[a+3]=Inv_Sbox2[tmp[a+3]];
1004 for(int a=0;a<h;a+=4) {
1005 invgY[a]=tmp[a]^fX[a]^IV2[a];
1006 invgY[a+1]=tmp[a+1]^fX[a+1]^IV2[a+1];
1007 invgY[a+2]=tmp[a+2]^fX[a+2]^IV2[a+2];
1008 invgY[a+3]=tmp[a+3]^fX[a+3]^IV2[a+3];
1013 for(int a=0;a<h;a+=4) {
1014 invgY[a]=Inv_Sbox2[Inv_Sbox1[gY[a]]^RM2[a]]^fX[a]^IV2[a];
1015 invgY[a+1]=Inv_Sbox2[Inv_Sbox1[gY[a+1]]^RM2[a+1]]^fX[a+1]^IV2[a+1];
1016 invgY[a+2]=Inv_Sbox2[Inv_Sbox1[gY[a+2]]^RM2[a+2]]^fX[a+2]^IV2[a+2];
1017 invgY[a+3]=Inv_Sbox2[Inv_Sbox1[gY[a+3]]^RM2[a+3]]^fX[a+3]^IV2[a+3];
1022 for(int a=0;a<h;a+=4) {
1023 tmp[a]=Inv_Sbox2[fX[a]]^invgY[a];
1024 tmp[a+1]=Inv_Sbox2[fX[a+1]]^invgY[a+1];
1025 tmp[a+2]=Inv_Sbox2[fX[a+2]]^invgY[a+2];
1026 tmp[a+3]=Inv_Sbox2[fX[a+3]]^invgY[a+3];
1031 for(int a=0;a<h;a+=4) {
1032 tmp[a]=Inv_Sbox1[tmp[a]];
1033 tmp[a+1]=Inv_Sbox1[tmp[a+1]];
1034 tmp[a+2]=Inv_Sbox1[tmp[a+2]];
1035 tmp[a+3]=Inv_Sbox1[tmp[a+3]];
1042 for(int a=0;a<h;a+=4) {
1043 invfX[a]=tmp[a]^RM1[a]^IV1[a];
1044 invfX[a+1]=tmp[a+1]^RM1[a+1]^IV1[a+1];
1045 invfX[a+2]=tmp[a+2]^RM1[a+2]^IV1[a+2];
1046 invfX[a+3]=tmp[a+3]^RM1[a+3]^IV1[a+3];
1051 for(int a=0;a<h;a+=4) {
1052 invfX[a]=Inv_Sbox1[Inv_Sbox2[fX[a]]^invgY[a]]^RM1[a]^IV1[a];
1053 invfX[a+1]=Inv_Sbox1[Inv_Sbox2[fX[a+1]]^invgY[a+1]]^RM1[a+1]^IV1[a+1];
1054 invfX[a+2]=Inv_Sbox1[Inv_Sbox2[fX[a+2]]^invgY[a+2]]^RM1[a+2]^IV1[a+2];
1055 invfX[a+3]=Inv_Sbox1[Inv_Sbox2[fX[a+3]]^invgY[a+3]]^RM1[a+3]^IV1[a+3];
1063 for(int a=0;a<h;a+=4) {
1064 seq_out[ind2+a]=invfX[a];
1065 seq_out[ind2+a+1]=invfX[a+1];
1066 seq_out[ind2+a+2]=invfX[a+2];
1067 seq_out[ind2+a+3]=invfX[a+3];
1070 for(int a=0;a<h;a+=4) {
1071 seq_out[ind1+a]=invgY[a];
1072 seq_out[ind1+a+1]=invgY[a+1];
1073 seq_out[ind1+a+2]=invgY[a+2];
1074 seq_out[ind1+a+3]=invgY[a+3];
1076 for(int a=0;a<h;a+=4) {
1083 for(int a=0;a<h;a+=4) {
1106 void encrypt_cbc_rm(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *IV, int debug) {
1120 for(int a=0;a<h;a+=4) {
1128 for(int a=0;a<h;a+=4) {
1138 for(int it=0;it<len/2;it++) {
1139 int ind1=Pbox[it]*h;
1140 int ind2=Pbox[it+len/2]*h;
1142 RM1=&RM[PboxSRM[it]*h];
1143 RM2=&RM[h*h+PboxSRM[len/2-it-1]*h];
1149 for(int a=0;a<h;a+=4) {
1150 X[a]=seq_in[ind2+a];
1151 X[a+1]=seq_in[ind2+a+1];
1152 X[a+2]=seq_in[ind2+a+2];
1153 X[a+3]=seq_in[ind2+a+3];
1156 for(int a=0;a<h;a+=4) {
1157 Y[a]=seq_in[ind1+a];
1158 Y[a+1]=seq_in[ind1+a+1];
1159 Y[a+2]=seq_in[ind1+a+2];
1160 Y[a+3]=seq_in[ind1+a+3];
1164 for(int a=0;a<h;a+=4) {
1165 tmp[a]=X[a]^RM1[a]^IV1[a];
1166 tmp[a+1]=X[a+1]^RM1[a+1]^IV1[a+1];
1167 tmp[a+2]=X[a+2]^RM1[a+2]^IV1[a+2];
1168 tmp[a+3]=X[a+3]^RM1[a+3]^IV1[a+3];
1171 for(int a=0;a<h;a+=4) {
1172 tmp[a]=Sbox1[tmp[a]];
1173 tmp[a+1]=Sbox1[tmp[a+1]];
1174 tmp[a+2]=Sbox1[tmp[a+2]];
1175 tmp[a+3]=Sbox1[tmp[a+3]];
1179 /*for(int a=0;a<h;a+=4) {
1180 tmp[a]=Sbox1[X[a]^RM1[a]^IV1[a]];
1181 tmp[a+1]=Sbox1[X[a+1]^RM1[a+1]^IV1[a+1]];
1182 tmp[a+2]=Sbox1[X[a+2]^RM1[a+2]^IV1[a+2]];
1183 tmp[a+3]=Sbox1[X[a+3]^RM1[a+3]^IV1[a+3]];
1186 for(int a=0;a<h;a+=4) {
1187 fX[a]=Sbox2[tmp[a]^Y[a]];
1188 fX[a+1]=Sbox2[tmp[a+1]^Y[a+1]];
1189 fX[a+2]=Sbox2[tmp[a+2]^Y[a+2]];
1190 fX[a+3]=Sbox2[tmp[a+3]^Y[a+3]];
1194 for(int a=0;a<h;a+=4) {
1195 fX[a]=Sbox2[Sbox1[X[a]^RM1[a]^IV1[a]]^Y[a]];
1196 fX[a+1]=Sbox2[Sbox1[X[a+1]^RM1[a+1]^IV1[a+1]]^Y[a+1]];
1197 fX[a+2]=Sbox2[Sbox1[X[a+2]^RM1[a+2]^IV1[a+2]]^Y[a+2]];
1198 fX[a+3]=Sbox2[Sbox1[X[a+3]^RM1[a+3]^IV1[a+3]]^Y[a+3]];
1202 for(int a=0;a<h;a+=4) {
1203 tmp[a]=fX[a]^Y[a]^IV2[a];
1204 tmp[a+1]=fX[a+1]^Y[a+1]^IV2[a+1];
1205 tmp[a+2]=fX[a+2]^Y[a+2]^IV2[a+2];
1206 tmp[a+3]=fX[a+3]^Y[a+3]^IV2[a+3];
1210 for(int a=0;a<h;a+=4) {
1211 tmp[a]=Sbox2[tmp[a]];
1212 tmp[a+1]=Sbox2[tmp[a+1]];
1213 tmp[a+2]=Sbox2[tmp[a+2]];
1214 tmp[a+3]=Sbox2[tmp[a+3]];
1219 for(int a=0;a<h;a+=4) {
1220 tmp[a]=Sbox2[fX[a]^Y[a]^IV2[a]];
1221 tmp[a+1]=Sbox2[fX[a+1]^Y[a+1]^IV2[a+1]];
1222 tmp[a+2]=Sbox2[fX[a+2]^Y[a+2]^IV2[a+2]];
1223 tmp[a+3]=Sbox2[fX[a+3]^Y[a+3]^IV2[a+3]];
1228 for(int a=0;a<h;a+=4) {
1229 gY[a]=Sbox1[tmp[a]^RM2[a]];
1230 gY[a+1]=Sbox1[tmp[a+1]^RM2[a+1]];
1231 gY[a+2]=Sbox1[tmp[a+2]^RM2[a+2]];
1232 gY[a+3]=Sbox1[tmp[a+3]^RM2[a+3]];
1239 for(int a=0;a<h;a+=4) {
1240 gY[a]=Sbox1[Sbox2[fX[a]^Y[a]^IV2[a]]^RM2[a]];
1241 gY[a+1]=Sbox1[Sbox2[fX[a+1]^Y[a+1]^IV2[a+1]]^RM2[a+1]];
1242 gY[a+2]=Sbox1[Sbox2[fX[a+2]^Y[a+2]^IV2[a+2]]^RM2[a+2]];
1243 gY[a+3]=Sbox1[Sbox2[fX[a+3]^Y[a+3]^IV2[a+3]]^RM2[a+3]];
1250 for(int a=0;a<h;a+=4) {
1251 seq_out[ind2+a]=gY[a];
1252 seq_out[ind2+a+1]=gY[a+1];
1253 seq_out[ind2+a+2]=gY[a+2];
1254 seq_out[ind2+a+3]=gY[a+3];
1257 for(int a=0;a<h;a+=4) {
1258 seq_out[ind1+a]=fX[a];
1259 seq_out[ind1+a+1]=fX[a+1];
1260 seq_out[ind1+a+2]=fX[a+2];
1261 seq_out[ind1+a+3]=fX[a+3];
1264 for(int a=0;a<h;a+=4) {
1271 for(int a=0;a<h;a+=4) {
1293 void decrypt_cbc_rm(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2, uchar *IV, int debug) {
1306 for(int a=0;a<h;a+=4) {
1314 for(int a=0;a<h;a+=4) {
1322 for(int it=0;it<len/2;it++) {
1323 int ind1=Pbox[it]*h;
1324 int ind2=Pbox[it+len/2]*h;
1327 RM1=&RM[PboxSRM[it]*h];
1328 RM2=&RM[h*h+PboxSRM[len/2-it-1]*h];
1333 for(int a=0;a<h;a+=4) {
1334 gY[a]=seq_in[ind2+a];
1335 gY[a+1]=seq_in[ind2+a+1];
1336 gY[a+2]=seq_in[ind2+a+2];
1337 gY[a+3]=seq_in[ind2+a+3];
1340 for(int a=0;a<h;a+=4) {
1341 fX[a]=seq_in[ind1+a];
1342 fX[a+1]=seq_in[ind1+a+1];
1343 fX[a+2]=seq_in[ind1+a+2];
1344 fX[a+3]=seq_in[ind1+a+3];
1348 for(int a=0;a<h;a+=4) {
1349 tmp[a]=Inv_Sbox1[gY[a]]^RM2[a];
1350 tmp[a+1]=Inv_Sbox1[gY[a+1]]^RM2[a+1];
1351 tmp[a+2]=Inv_Sbox1[gY[a+2]]^RM2[a+2];
1352 tmp[a+3]=Inv_Sbox1[gY[a+3]]^RM2[a+3];
1356 for(int a=0;a<h;a+=4) {
1357 tmp[a]=Inv_Sbox2[tmp[a]];
1358 tmp[a+1]=Inv_Sbox2[tmp[a+1]];
1359 tmp[a+2]=Inv_Sbox2[tmp[a+2]];
1360 tmp[a+3]=Inv_Sbox2[tmp[a+3]];
1365 for(int a=0;a<h;a+=4) {
1366 invgY[a]=tmp[a]^fX[a]^IV2[a];
1367 invgY[a+1]=tmp[a+1]^fX[a+1]^IV2[a+1];
1368 invgY[a+2]=tmp[a+2]^fX[a+2]^IV2[a+2];
1369 invgY[a+3]=tmp[a+3]^fX[a+3]^IV2[a+3];
1373 for(int a=0;a<h;a+=4) {
1374 tmp[a]=Inv_Sbox2[fX[a]]^invgY[a];
1375 tmp[a+1]=Inv_Sbox2[fX[a+1]]^invgY[a+1];
1376 tmp[a+2]=Inv_Sbox2[fX[a+2]]^invgY[a+2];
1377 tmp[a+3]=Inv_Sbox2[fX[a+3]]^invgY[a+3];
1382 for(int a=0;a<h;a+=4) {
1383 tmp[a]=Inv_Sbox1[tmp[a]];
1384 tmp[a+1]=Inv_Sbox1[tmp[a+1]];
1385 tmp[a+2]=Inv_Sbox1[tmp[a+2]];
1386 tmp[a+3]=Inv_Sbox1[tmp[a+3]];
1393 for(int a=0;a<h;a+=4) {
1394 invfX[a]=tmp[a]^RM1[a]^IV1[a];
1395 invfX[a+1]=tmp[a+1]^RM1[a+1]^IV1[a+1];
1396 invfX[a+2]=tmp[a+2]^RM1[a+2]^IV1[a+2];
1397 invfX[a+3]=tmp[a+3]^RM1[a+3]^IV1[a+3];
1402 for(int a=0;a<h;a+=4) {
1403 seq_out[ind2+a]=invfX[a];
1404 seq_out[ind2+a+1]=invfX[a+1];
1405 seq_out[ind2+a+2]=invfX[a+2];
1406 seq_out[ind2+a+3]=invfX[a+3];
1409 for(int a=0;a<h;a+=4) {
1410 seq_out[ind1+a]=invgY[a];
1411 seq_out[ind1+a+1]=invgY[a+1];
1412 seq_out[ind1+a+2]=invgY[a+2];
1413 seq_out[ind1+a+3]=invgY[a+3];
1415 for(int a=0;a<h;a+=4) {
1422 for(int a=0;a<h;a+=4) {
1442 int main(int argc, char** argv) {
1451 for(int i=1; i<argc; i++){
1452 if(strncmp(argv[i],"nb",2)==0) nb_test = atoi(&(argv[i][2])); //nb of test
1453 if(strncmp(argv[i],"cbcrm",5)==0) cbcrm=1;
1454 if(strncmp(argv[i],"cbcprng",7)==0) {cbcprng=1;cbcrm=0;}
1455 if(strncmp(argv[i],"ecbrm",5)==0) ecbrm = 1;
1456 if(strncmp(argv[i],"ecbprng",7)==0) {ecbprng=1; ecbrm=0;}
1457 if(strncmp(argv[i],"h",1)==0) h = atoi(&(argv[i][1])); //size of block
1458 if(strncmp(argv[i],"sizebuf",7)==0) size_buf = atoi(&(argv[i][7])); //SIZE of the buffer
1459 if(strncmp(argv[i],"lena",4)==0) lena = atoi(&(argv[i][4])); //Use Lena or buffer
1462 /* printf("nb times %d\n",nb_test);
1463 printf("cbcrm %d\n",cbcrm);
1464 printf("cbcprng %d\n",cbcprng);
1465 printf("ecbrm %d\n",ecbrm);
1466 printf("ecbprng %d\n",ecbprng);
1468 printf("lena %d\n",lena);
1469 printf("size_buf %d\n",size_buf);
1474 int seed=time(NULL);
1475 // cout<<seed<<endl;
1478 uchar Secretkey[key_size];
1480 uchar counter[key_size];
1482 for(int i=0;i<key_size;i++) {
1483 Secretkey[i]=lrand48()&0xFF;
1484 counter[i]=lrand48()&0xFF;
1497 uchar *data_R, *data_G, *data_B;
1506 load_RGB_pixmap("lena.ppm", &width, &height, &data_R, &data_G, &data_B);
1507 // load_RGB_pixmap("8192.ppm", &width, &height, &data_R, &data_G, &data_B);
1508 imsize=width*height*3;
1509 // load_RGB_pixmap("No_ecb_mode_picture.ppm", &width, &height, &data_R, &data_G, &data_B);
1512 width=height=size_buf;
1513 imsize=width*height*3;
1514 //cout<<"imsize "<<imsize<<endl;
1515 buffer=new uchar[imsize];
1516 for(int i=0;i<imsize;i++) {
1517 buffer[i]=lrand48();
1523 cout<<"imsize "<<imsize<<endl;
1525 uchar* seq= new uchar[imsize];
1526 uchar* seq2= new uchar[imsize];
1528 int oneD=width*height;
1530 for(int i=0;i<oneD;i++) {
1532 seq[oneD+i]=data_G[i];
1533 seq[2*oneD+i]=data_B[i];
1537 for(int i=0;i<oneD;i++) {
1546 int total_len=imsize;
1548 int len= total_len/h;
1552 uchar *mix=new uchar[256];
1557 for (int i = 0; i < 256 ; i++) {
1558 mix[i]=Secretkey[i]^counter[i];
1563 sha512 = g_compute_checksum_for_string(G_CHECKSUM_SHA512, (const char*) mix, 256);
1564 // g_print("%s\n", sha512);
1574 // cout<<"hash "<<endl;
1575 for (int i = 0; i < 128 ; i++) {
1582 int *Pbox=new int[len];
1583 int *PboxSRM=new int[len/2];
1584 int *PboxSRM2=new int[len/2];
1587 uchar Inv_Sbox1[256];
1588 uchar Inv_Sbox2[256];
1590 uchar RM[h*h*2+256];
1596 double time_encrypt=0;
1597 double time_decrypt=0;
1600 double t=TimeStart();
1602 for(int i=0;i<nb_test;i++) {
1604 rc4key(DK, Sbox1, 8);
1607 rc4key(&DK[8], Sbox2, 8);
1609 rc4key(&DK[16], sc, 16);
1610 prga(sc, h*h*2+256, RM);
1616 rc4keyperm(&DK[72], len, rp, Pbox, 16);
1619 rc4keyperm(&DK[88], len/2, rp, PboxSRM2, 16);
1621 for(int i=0;i<len/2;i++) {
1622 PboxSRM[i]=PboxSRM2[i]&(h-1);
1626 for(int i=0;i<h*2;i++) {
1627 for(int j=0;j<h;j++)
1628 cout<<(int)RM[i*h+j]<<" ";
1635 time_init+=TimeStop(t);
1636 cout<<"Time initializaton nb times "<<nb_test<<" = "<<time_init<<endl;
1641 for(int i=0;i<64;i++) {
1652 inverse_tables(Sbox1,256,Inv_Sbox1);
1653 inverse_tables(Sbox2,256,Inv_Sbox2);
1657 // lehmer64_seed(myrand);
1664 for(i=0;i<nb_test;i++)
1667 encrypt_cbc_prng<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
1669 encrypt_cbc_rm<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
1671 encrypt_ecb_rm<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
1673 encrypt_ecb_prng<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
1677 for(i=0;i<nb_test;i++)
1680 encrypt_cbc_prng<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
1682 encrypt_cbc_rm<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
1684 encrypt_ecb_rm<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
1686 encrypt_ecb_prng<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
1690 for(i=0;i<nb_test;i++)
1693 encrypt_cbc_prng<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
1695 encrypt_cbc_rm<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
1697 encrypt_ecb_rm<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
1699 encrypt_ecb_prng<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
1703 for(i=0;i<nb_test;i++)
1706 encrypt_cbc_prng<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
1708 encrypt_cbc_rm<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
1710 encrypt_ecb_rm<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
1712 encrypt_ecb_prng<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
1716 for(i=0;i<nb_test;i++)
1719 encrypt_cbc_prng<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
1721 encrypt_cbc_rm<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
1723 encrypt_ecb_rm<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
1725 encrypt_ecb_prng<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
1730 for(i=0;i<nb_test;i++)
1733 encrypt_cbc_prng<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
1735 encrypt_cbc_rm<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
1737 encrypt_ecb_rm<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
1739 encrypt_ecb_prng<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
1745 for(i=0;i<nb_test;i++)
1748 encrypt_cbc_prng<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
1750 encrypt_cbc_rm<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
1752 encrypt_ecb_rm<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,0);
1754 encrypt_ecb_prng<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,IV,myrand,0);
1761 time_encrypt+=TimeStop(t);
1762 cout<<"Time encrypt "<<time_encrypt<<endl;
1763 cout<<(double)imsize*nb_test/time_encrypt<<"\t";
1767 for(int i=0;i<oneD;i++) {
1769 data_G[i]=seq2[oneD+i];
1770 data_B[i]=seq2[2*oneD+i];
1772 store_RGB_pixmap("lena2.ppm", data_R, data_G, data_B, width, height);
1777 // lehmer64_seed(myrand);
1782 for(i=0;i<nb_test;i++) {
1784 decrypt_cbc_prng<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
1786 decrypt_cbc_rm<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
1788 decrypt_ecb_rm<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
1790 decrypt_ecb_prng<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
1794 for(i=0;i<nb_test;i++) {
1796 decrypt_cbc_prng<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
1798 decrypt_cbc_rm<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
1800 decrypt_ecb_rm<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
1802 decrypt_ecb_prng<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
1806 for(i=0;i<nb_test;i++) {
1808 decrypt_cbc_prng<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
1810 decrypt_cbc_rm<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
1812 decrypt_ecb_rm<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
1814 decrypt_ecb_prng<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
1818 for(i=0;i<nb_test;i++) {
1820 decrypt_cbc_prng<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
1822 decrypt_cbc_rm<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
1824 decrypt_ecb_rm<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
1826 decrypt_ecb_prng<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
1830 for(i=0;i<nb_test;i++) {
1832 decrypt_cbc_prng<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
1834 decrypt_cbc_rm<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
1836 decrypt_ecb_rm<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
1838 decrypt_ecb_prng<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
1842 for(i=0;i<nb_test;i++) {
1844 decrypt_cbc_prng<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
1846 decrypt_cbc_rm<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
1848 decrypt_ecb_rm<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
1850 decrypt_ecb_prng<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
1854 for(i=0;i<nb_test;i++) {
1856 decrypt_cbc_prng<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
1858 decrypt_cbc_rm<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
1860 decrypt_ecb_rm<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,0);
1862 decrypt_ecb_prng<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,IV,myrand,0);
1869 time_decrypt+=TimeStop(t);
1870 // cout<<"Time decrypt "<<time_decrypt<<endl;
1871 cout<<(double)imsize*nb_test/time_decrypt<<"\t";
1874 for(int i=0;i<oneD;i++) {
1876 data_G[i]=seq[oneD+i];
1877 data_B[i]=seq[2*oneD+i];
1879 store_RGB_pixmap("lena3.ppm", data_R, data_G, data_B, width, height);
1883 for(int i=0;i<imsize;i++) {
1884 //cout<<(int)buffer[i]<<endl;
1885 if(buffer[i]!=seq[i]) {
1889 //cout<<"RESULT CORRECT: "<<equal<<endl;