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;
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" */
76 ulong xorshift64(ulong t)
78 /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
88 __uint128_t g_lehmer64_state;
90 inline uint64_t splitmix64_stateless(uint64_t index) {
91 uint64_t z = (index + UINT64_C(0x9E3779B97F4A7C15));
92 z = (z ^ (z >> 30)) * UINT64_C(0xBF58476D1CE4E5B9);
93 z = (z ^ (z >> 27)) * UINT64_C(0x94D049BB133111EB);
98 inline void lehmer64_seed(uint64_t seed) {
99 g_lehmer64_state = (((__uint128_t)splitmix64_stateless(seed)) << 64) +
100 splitmix64_stateless(seed + 1);
103 inline uint64_t lehmer64() {
104 g_lehmer64_state *= UINT64_C(0xda942042e4dd58b5);
106 return g_lehmer64_state >> 64;
113 void inverse_tables(uchar *tab, int size_tab,uchar *inv_perm_tabs) {
115 for(int i=0;i<size_tab;i++) {
116 inv_perm_tabs[tab[i]] = i;
121 void inverse_tables_int(int *tab, int size_tab,int *inv_perm_tabs) {
123 for(int i=0;i<size_tab;i++) {
124 inv_perm_tabs[tab[i]] = i;
131 void rc4key(uchar *key, uchar *sc, int size_DK) {
133 for(int i=0;i<256;i++) {
139 for(int i0=0; i0<256; i0++) {
140 j0 = (j0 + sc[i0] + key[i0%size_DK] )&0xFF;
149 void rc4keyperm(uchar *key,int len, int rp,int *sc, int size_DK) {
155 for (int i=0;i<len;i++) {
158 for (int it = 0; it < rp; it++) {
160 for(int i0 = 0; i0<len; i0++) {
161 j0 = (j0 + sc[i0] + sc[j0] + key[i0%size_DK] )% len;
170 void prga(uchar *sc, int ldata, uchar *r) {
174 for (int it=0; it<ldata; it++) {
176 j0 = (j0 + sc[i0])&0xFF;
180 r[it]=sc[(sc[i0]+sc[j0])&0xFF];
190 void encrypt_ecb(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, ulong myrand, int debug) {
199 ulong *rm1=(ulong*)RM1;
200 ulong *rm2=(ulong*)RM2;
202 for(int it=0;it<len/2;it++) {
204 int ind2=Pbox[it+len/2]*h;
207 for(int a=0;a<(h>>3);a++) {
216 for(int a=0;a<h;a+=4) {
218 X[a+1]=seq_in[ind2+a+1];
219 X[a+2]=seq_in[ind2+a+2];
220 X[a+3]=seq_in[ind2+a+3];
223 for(int a=0;a<h;a+=4) {
225 Y[a+1]=seq_in[ind1+a+1];
226 Y[a+2]=seq_in[ind1+a+2];
227 Y[a+3]=seq_in[ind1+a+3];
231 for(int a=0;a<h;a+=4) {
232 tmp[a]=Sbox1[X[a]^RM1[a]];
233 tmp[a+1]=Sbox1[X[a+1]^RM1[a+1]];
234 tmp[a+2]=Sbox1[X[a+2]^RM1[a+2]];
235 tmp[a+3]=Sbox1[X[a+3]^RM1[a+3]];
238 for(int a=0;a<h;a+=4) {
239 fX[a]=Sbox2[tmp[a]^Y[a]];
240 fX[a+1]=Sbox2[tmp[a+1]^Y[a+1]];
241 fX[a+2]=Sbox2[tmp[a+2]^Y[a+2]];
242 fX[a+3]=Sbox2[tmp[a+3]^Y[a+3]];
246 /*for(int a=0;a<h;a+=4) {
247 fX[a]=Sbox2[Sbox1[X[a]^RM1[a]]^Y[a]];
248 fX[a+1]=Sbox2[Sbox1[X[a+1]^RM1[a+1]]^Y[a+1]];
249 fX[a+2]=Sbox2[Sbox1[X[a+2]^RM1[a+2]]^Y[a+2]];
250 fX[a+3]=Sbox2[Sbox1[X[a+3]^RM1[a+3]]^Y[a+3]];
256 for(int a=0;a<h;a+=4) {
257 tmp[a]=Sbox2[fX[a]^Y[a]];
258 tmp[a+1]=Sbox2[fX[a+1]^Y[a+1]];
259 tmp[a+2]=Sbox2[fX[a+2]^Y[a+2]];
260 tmp[a+3]=Sbox2[fX[a+3]^Y[a+3]];
263 for(int a=0;a<h;a+=4) {
264 gY[a]=Sbox1[tmp[a]^RM2[a]];
265 gY[a+1]=Sbox1[tmp[a+1]^RM2[a+1]];
266 gY[a+2]=Sbox1[tmp[a+2]^RM2[a+2]];
267 gY[a+3]=Sbox1[tmp[a+3]^RM2[a+3]];
272 /* for(int a=0;a<h;a+=4) {
273 gY[a]=Sbox1[Sbox2[fX[a]^Y[a]]^RM2[a]];
274 gY[a+1]=Sbox1[Sbox2[fX[a+1]^Y[a+1]]^RM2[a+1]];
275 gY[a+2]=Sbox1[Sbox2[fX[a+2]^Y[a+2]]^RM2[a+2]];
276 gY[a+3]=Sbox1[Sbox2[fX[a+3]^Y[a+3]]^RM2[a+3]];
285 for(int a=0;a<h;a+=4) {
286 seq_out[ind2+a]=gY[a];
287 seq_out[ind2+a+1]=gY[a+1];
288 seq_out[ind2+a+2]=gY[a+2];
289 seq_out[ind2+a+3]=gY[a+3];
292 for(int a=0;a<h;a+=4) {
293 seq_out[ind1+a]=fX[a];
294 seq_out[ind1+a+1]=fX[a+1];
295 seq_out[ind1+a+2]=fX[a+2];
296 seq_out[ind1+a+3]=fX[a+3];
316 void decrypt_ecb(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2, ulong myrand, int debug) {
325 ulong *rm1=(ulong*)RM1;
326 ulong *rm2=(ulong*)RM2;
328 for(int it=0;it<len/2;it++) {
330 int ind2=Pbox[it+len/2]*h;
333 for(int a=0;a<(h>>3);a++) {
342 for(int a=0;a<h;a+=4) {
343 gY[a]=seq_in[ind2+a];
344 gY[a+1]=seq_in[ind2+a+1];
345 gY[a+2]=seq_in[ind2+a+2];
346 gY[a+3]=seq_in[ind2+a+3];
349 for(int a=0;a<h;a+=4) {
350 fX[a]=seq_in[ind1+a];
351 fX[a+1]=seq_in[ind1+a+1];
352 fX[a+2]=seq_in[ind1+a+2];
353 fX[a+3]=seq_in[ind1+a+3];
359 for(int a=0;a<h;a+=4) {
360 tmp[a]=Inv_Sbox1[gY[a]]^RM2[a];
361 tmp[a+1]=Inv_Sbox1[gY[a+1]]^RM2[a+1];
362 tmp[a+2]=Inv_Sbox1[gY[a+2]]^RM2[a+2];
363 tmp[a+3]=Inv_Sbox1[gY[a+3]]^RM2[a+3];
367 for(int a=0;a<h;a+=4) {
368 invgY[a]=Inv_Sbox2[tmp[a]]^fX[a];
369 invgY[a+1]=Inv_Sbox2[tmp[a+1]]^fX[a+1];
370 invgY[a+2]=Inv_Sbox2[tmp[a+2]]^fX[a+2];
371 invgY[a+3]=Inv_Sbox2[tmp[a+3]]^fX[a+3];
376 /* for(int a=0;a<h;a+=4) {
377 invgY[a]=Inv_Sbox2[Inv_Sbox1[gY[a]]^RM2[a]]^fX[a];
378 invgY[a+1]=Inv_Sbox2[Inv_Sbox1[gY[a+1]]^RM2[a+1]]^fX[a+1];
379 invgY[a+2]=Inv_Sbox2[Inv_Sbox1[gY[a+2]]^RM2[a+2]]^fX[a+2];
380 invgY[a+3]=Inv_Sbox2[Inv_Sbox1[gY[a+3]]^RM2[a+3]]^fX[a+3];
386 for(int a=0;a<h;a+=4) {
387 tmp[a]=Inv_Sbox2[fX[a]]^invgY[a];
388 tmp[a+1]=Inv_Sbox2[fX[a+1]]^invgY[a+1];
389 tmp[a+2]=Inv_Sbox2[fX[a+2]]^invgY[a+2];
390 tmp[a+3]=Inv_Sbox2[fX[a+3]]^invgY[a+3];
394 for(int a=0;a<h;a+=4) {
395 invfX[a]=Inv_Sbox1[tmp[a]]^RM1[a];
396 invfX[a+1]=Inv_Sbox1[tmp[a+1]]^RM1[a+1];
397 invfX[a+2]=Inv_Sbox1[tmp[a+2]]^RM1[a+2];
398 invfX[a+3]=Inv_Sbox1[tmp[a+3]]^RM1[a+3];
404 for(int a=0;a<h;a+=4) {
405 invfX[a]=Inv_Sbox1[Inv_Sbox2[fX[a]]^invgY[a]]^RM1[a];
406 invfX[a+1]=Inv_Sbox1[Inv_Sbox2[fX[a+1]]^invgY[a+1]]^RM1[a+1];
407 invfX[a+2]=Inv_Sbox1[Inv_Sbox2[fX[a+2]]^invgY[a+2]]^RM1[a+2];
408 invfX[a+3]=Inv_Sbox1[Inv_Sbox2[fX[a+3]]^invgY[a+3]]^RM1[a+3];
413 for(int a=0;a<h;a+=4) {
414 seq_out[ind2+a]=invfX[a];
415 seq_out[ind2+a+1]=invfX[a+1];
416 seq_out[ind2+a+2]=invfX[a+2];
417 seq_out[ind2+a+3]=invfX[a+3];
420 for(int a=0;a<h;a+=4) {
421 seq_out[ind1+a]=invgY[a];
422 seq_out[ind1+a+1]=invgY[a+1];
423 seq_out[ind1+a+2]=invgY[a+2];
424 seq_out[ind1+a+3]=invgY[a+3];
441 void encrypt_ecb(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uint myrand, int debug) {
450 for(int it=0;it<len/2;it++) {
452 int ind2=Pbox[it+len/2]*h;
456 RM1=&RM[PboxSRM[it]*h];
457 RM2=&RM[h*h+PboxSRM[it]*h];
460 for(int a=0;a<h;a+=4) {
462 X[a+1]=seq_in[ind2+a+1];
463 X[a+2]=seq_in[ind2+a+2];
464 X[a+3]=seq_in[ind2+a+3];
467 for(int a=0;a<h;a+=4) {
469 Y[a+1]=seq_in[ind1+a+1];
470 Y[a+2]=seq_in[ind1+a+2];
471 Y[a+3]=seq_in[ind1+a+3];
475 for(int a=0;a<h;a+=4) {
476 fX[a]=Sbox2[Sbox1[X[a]^RM1[a]]^Y[a]];
477 fX[a+1]=Sbox2[Sbox1[X[a+1]^RM1[a+1]]^Y[a+1]];
478 fX[a+2]=Sbox2[Sbox1[X[a+2]^RM1[a+2]]^Y[a+2]];
479 fX[a+3]=Sbox2[Sbox1[X[a+3]^RM1[a+3]]^Y[a+3]];
482 for(int a=0;a<h;a+=4) {
483 gY[a]=Sbox1[Sbox2[fX[a]^Y[a]]^RM2[a]];
484 gY[a+1]=Sbox1[Sbox2[fX[a+1]^Y[a+1]]^RM2[a+1]];
485 gY[a+2]=Sbox1[Sbox2[fX[a+2]^Y[a+2]]^RM2[a+2]];
486 gY[a+3]=Sbox1[Sbox2[fX[a+3]^Y[a+3]]^RM2[a+3]];
490 for(int a=0;a<h;a+=4) {
491 seq_out[ind2+a]=gY[a];
492 seq_out[ind2+a+1]=gY[a+1];
493 seq_out[ind2+a+2]=gY[a+2];
494 seq_out[ind2+a+3]=gY[a+3];
497 for(int a=0;a<h;a+=4) {
498 seq_out[ind1+a]=fX[a];
499 seq_out[ind1+a+1]=fX[a+1];
500 seq_out[ind1+a+2]=fX[a+2];
501 seq_out[ind1+a+3]=fX[a+3];
521 void decrypt_ecb(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2, uint myrand, int debug) {
530 for(int it=0;it<len/2;it++) {
532 int ind2=Pbox[it+len/2]*h;
535 RM1=&RM[PboxSRM[it]*h];
536 RM2=&RM[h*h+PboxSRM[it]*h];
539 for(int a=0;a<h;a+=4) {
540 gY[a]=seq_in[ind2+a];
541 gY[a+1]=seq_in[ind2+a+1];
542 gY[a+2]=seq_in[ind2+a+2];
543 gY[a+3]=seq_in[ind2+a+3];
546 for(int a=0;a<h;a+=4) {
547 fX[a]=seq_in[ind1+a];
548 fX[a+1]=seq_in[ind1+a+1];
549 fX[a+2]=seq_in[ind1+a+2];
550 fX[a+3]=seq_in[ind1+a+3];
553 for(int a=0;a<h;a+=4) {
554 invgY[a]=Inv_Sbox2[Inv_Sbox1[gY[a]]^RM2[a]]^fX[a];
555 invgY[a+1]=Inv_Sbox2[Inv_Sbox1[gY[a+1]]^RM2[a+1]]^fX[a+1];
556 invgY[a+2]=Inv_Sbox2[Inv_Sbox1[gY[a+2]]^RM2[a+2]]^fX[a+2];
557 invgY[a+3]=Inv_Sbox2[Inv_Sbox1[gY[a+3]]^RM2[a+3]]^fX[a+3];
562 for(int a=0;a<h;a+=4) {
563 invfX[a]=Inv_Sbox1[Inv_Sbox2[fX[a]]^invgY[a]]^RM1[a];
564 invfX[a+1]=Inv_Sbox1[Inv_Sbox2[fX[a+1]]^invgY[a+1]]^RM1[a+1];
565 invfX[a+2]=Inv_Sbox1[Inv_Sbox2[fX[a+2]]^invgY[a+2]]^RM1[a+2];
566 invfX[a+3]=Inv_Sbox1[Inv_Sbox2[fX[a+3]]^invgY[a+3]]^RM1[a+3];
571 for(int a=0;a<h;a+=4) {
572 seq_out[ind2+a]=invfX[a];
573 seq_out[ind2+a+1]=invfX[a+1];
574 seq_out[ind2+a+2]=invfX[a+2];
575 seq_out[ind2+a+3]=invfX[a+3];
578 for(int a=0;a<h;a+=4) {
579 seq_out[ind1+a]=invgY[a];
580 seq_out[ind1+a+1]=invgY[a+1];
581 seq_out[ind1+a+2]=invgY[a+2];
582 seq_out[ind1+a+3]=invgY[a+3];
601 void encrypt_cbc_prng(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uint myrand, int debug) {
612 ulong *rm1=(ulong*)RM1;
613 ulong *rm2=(ulong*)RM2;
615 for(int it=0;it<len/2;it++) {
617 int ind2=Pbox[it+len/2]*h;
620 for(int a=0;a<(h>>3);a++) {
629 for(int a=0;a<h;a+=4) {
631 X[a+1]=seq_in[ind2+a+1];
632 X[a+2]=seq_in[ind2+a+2];
633 X[a+3]=seq_in[ind2+a+3];
636 for(int a=0;a<h;a+=4) {
638 Y[a+1]=seq_in[ind1+a+1];
639 Y[a+2]=seq_in[ind1+a+2];
640 Y[a+3]=seq_in[ind1+a+3];
644 for(int a=0;a<h;a+=4) {
645 tmp[a]=X[a]^RM1[a]^IV1[a];
646 tmp[a+1]=X[a+1]^RM1[a+1]^IV1[a+1];
647 tmp[a+2]=X[a+2]^RM1[a+2]^IV1[a+2];
648 tmp[a+3]=X[a+3]^RM1[a+3]^IV1[a+3];
651 for(int a=0;a<h;a+=4) {
652 tmp[a]=Sbox1[tmp[a]];
653 tmp[a+1]=Sbox1[tmp[a+1]];
654 tmp[a+2]=Sbox1[tmp[a+2]];
655 tmp[a+3]=Sbox1[tmp[a+3]];
659 /*for(int a=0;a<h;a+=4) {
660 tmp[a]=Sbox1[X[a]^RM1[a]^IV1[a]];
661 tmp[a+1]=Sbox1[X[a+1]^RM1[a+1]^IV1[a+1]];
662 tmp[a+2]=Sbox1[X[a+2]^RM1[a+2]^IV1[a+2]];
663 tmp[a+3]=Sbox1[X[a+3]^RM1[a+3]^IV1[a+3]];
666 for(int a=0;a<h;a+=4) {
667 fX[a]=Sbox2[tmp[a]^Y[a]];
668 fX[a+1]=Sbox2[tmp[a+1]^Y[a+1]];
669 fX[a+2]=Sbox2[tmp[a+2]^Y[a+2]];
670 fX[a+3]=Sbox2[tmp[a+3]^Y[a+3]];
674 for(int a=0;a<h;a+=4) {
675 fX[a]=Sbox2[Sbox1[X[a]^RM1[a]^IV1[a]]^Y[a]];
676 fX[a+1]=Sbox2[Sbox1[X[a+1]^RM1[a+1]^IV1[a+1]]^Y[a+1]];
677 fX[a+2]=Sbox2[Sbox1[X[a+2]^RM1[a+2]^IV1[a+2]]^Y[a+2]];
678 fX[a+3]=Sbox2[Sbox1[X[a+3]^RM1[a+3]^IV1[a+3]]^Y[a+3]];
682 for(int a=0;a<h;a+=4) {
683 tmp[a]=fX[a]^Y[a]^IV2[a];
684 tmp[a+1]=fX[a+1]^Y[a+1]^IV2[a+1];
685 tmp[a+2]=fX[a+2]^Y[a+2]^IV2[a+2];
686 tmp[a+3]=fX[a+3]^Y[a+3]^IV2[a+3];
690 for(int a=0;a<h;a+=4) {
691 tmp[a]=Sbox2[tmp[a]];
692 tmp[a+1]=Sbox2[tmp[a+1]];
693 tmp[a+2]=Sbox2[tmp[a+2]];
694 tmp[a+3]=Sbox2[tmp[a+3]];
699 for(int a=0;a<h;a+=4) {
700 tmp[a]=Sbox2[fX[a]^Y[a]^IV2[a]];
701 tmp[a+1]=Sbox2[fX[a+1]^Y[a+1]^IV2[a+1]];
702 tmp[a+2]=Sbox2[fX[a+2]^Y[a+2]^IV2[a+2]];
703 tmp[a+3]=Sbox2[fX[a+3]^Y[a+3]^IV2[a+3]];
708 for(int a=0;a<h;a+=4) {
709 gY[a]=Sbox1[tmp[a]^RM2[a]];
710 gY[a+1]=Sbox1[tmp[a+1]^RM2[a+1]];
711 gY[a+2]=Sbox1[tmp[a+2]^RM2[a+2]];
712 gY[a+3]=Sbox1[tmp[a+3]^RM2[a+3]];
719 for(int a=0;a<h;a+=4) {
720 gY[a]=Sbox1[Sbox2[fX[a]^Y[a]^IV2[a]]^RM2[a]];
721 gY[a+1]=Sbox1[Sbox2[fX[a+1]^Y[a+1]^IV2[a+1]]^RM2[a+1]];
722 gY[a+2]=Sbox1[Sbox2[fX[a+2]^Y[a+2]^IV2[a+2]]^RM2[a+2]];
723 gY[a+3]=Sbox1[Sbox2[fX[a+3]^Y[a+3]^IV2[a+3]]^RM2[a+3]];
728 for(int a=0;a<h;a+=4) {
729 seq_out[ind2+a]=gY[a];
730 seq_out[ind2+a+1]=gY[a+1];
731 seq_out[ind2+a+2]=gY[a+2];
732 seq_out[ind2+a+3]=gY[a+3];
735 for(int a=0;a<h;a+=4) {
736 seq_out[ind1+a]=fX[a];
737 seq_out[ind1+a+1]=fX[a+1];
738 seq_out[ind1+a+2]=fX[a+2];
739 seq_out[ind1+a+3]=fX[a+3];
741 for(int a=0;a<h;a+=4) {
748 for(int a=0;a<h;a+=4) {
770 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, uint myrand, int debug) {
781 ulong *rm1=(ulong*)RM1;
782 ulong *rm2=(ulong*)RM2;
784 for(int it=0;it<len/2;it++) {
786 int ind2=Pbox[it+len/2]*h;
789 for(int a=0;a<(h>>3);a++) {
796 for(int a=0;a<h;a+=4) {
797 gY[a]=seq_in[ind2+a];
798 gY[a+1]=seq_in[ind2+a+1];
799 gY[a+2]=seq_in[ind2+a+2];
800 gY[a+3]=seq_in[ind2+a+3];
803 for(int a=0;a<h;a+=4) {
804 fX[a]=seq_in[ind1+a];
805 fX[a+1]=seq_in[ind1+a+1];
806 fX[a+2]=seq_in[ind1+a+2];
807 fX[a+3]=seq_in[ind1+a+3];
811 for(int a=0;a<h;a+=4) {
812 tmp[a]=Inv_Sbox1[gY[a]]^RM2[a];
813 tmp[a+1]=Inv_Sbox1[gY[a+1]]^RM2[a+1];
814 tmp[a+2]=Inv_Sbox1[gY[a+2]]^RM2[a+2];
815 tmp[a+3]=Inv_Sbox1[gY[a+3]]^RM2[a+3];
819 for(int a=0;a<h;a+=4) {
820 tmp[a]=Inv_Sbox2[tmp[a]];
821 tmp[a+1]=Inv_Sbox2[tmp[a+1]];
822 tmp[a+2]=Inv_Sbox2[tmp[a+2]];
823 tmp[a+3]=Inv_Sbox2[tmp[a+3]];
828 for(int a=0;a<h;a+=4) {
829 invgY[a]=tmp[a]^fX[a]^IV2[a];
830 invgY[a+1]=tmp[a+1]^fX[a+1]^IV2[a+1];
831 invgY[a+2]=tmp[a+2]^fX[a+2]^IV2[a+2];
832 invgY[a+3]=tmp[a+3]^fX[a+3]^IV2[a+3];
836 for(int a=0;a<h;a+=4) {
837 tmp[a]=Inv_Sbox2[fX[a]]^invgY[a];
838 tmp[a+1]=Inv_Sbox2[fX[a+1]]^invgY[a+1];
839 tmp[a+2]=Inv_Sbox2[fX[a+2]]^invgY[a+2];
840 tmp[a+3]=Inv_Sbox2[fX[a+3]]^invgY[a+3];
845 for(int a=0;a<h;a+=4) {
846 tmp[a]=Inv_Sbox1[tmp[a]];
847 tmp[a+1]=Inv_Sbox1[tmp[a+1]];
848 tmp[a+2]=Inv_Sbox1[tmp[a+2]];
849 tmp[a+3]=Inv_Sbox1[tmp[a+3]];
856 for(int a=0;a<h;a+=4) {
857 invfX[a]=tmp[a]^RM1[a]^IV1[a];
858 invfX[a+1]=tmp[a+1]^RM1[a+1]^IV1[a+1];
859 invfX[a+2]=tmp[a+2]^RM1[a+2]^IV1[a+2];
860 invfX[a+3]=tmp[a+3]^RM1[a+3]^IV1[a+3];
865 for(int a=0;a<h;a+=4) {
866 seq_out[ind2+a]=invfX[a];
867 seq_out[ind2+a+1]=invfX[a+1];
868 seq_out[ind2+a+2]=invfX[a+2];
869 seq_out[ind2+a+3]=invfX[a+3];
872 for(int a=0;a<h;a+=4) {
873 seq_out[ind1+a]=invgY[a];
874 seq_out[ind1+a+1]=invgY[a+1];
875 seq_out[ind1+a+2]=invgY[a+2];
876 seq_out[ind1+a+3]=invgY[a+3];
878 for(int a=0;a<h;a+=4) {
885 for(int a=0;a<h;a+=4) {
908 void encrypt_cbc_rm(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uint myrand, int debug) {
920 for(int a=0;a<h;a+=4) {
927 for(int a=0;a<h;a+=4) {
929 IV2[a+1]=RM[h*h+a+1];
930 IV2[a+2]=RM[h*h+a+2];
931 IV2[a+3]=RM[h*h+a+3];
937 for(int it=0;it<len/2;it++) {
939 int ind2=Pbox[it+len/2]*h;
941 RM1=&RM[PboxSRM[it]*h];
942 RM2=&RM[h*h+PboxSRM[it]*h];
944 for(int a=0;a<h;a+=4) {
946 X[a+1]=seq_in[ind2+a+1];
947 X[a+2]=seq_in[ind2+a+2];
948 X[a+3]=seq_in[ind2+a+3];
951 for(int a=0;a<h;a+=4) {
953 Y[a+1]=seq_in[ind1+a+1];
954 Y[a+2]=seq_in[ind1+a+2];
955 Y[a+3]=seq_in[ind1+a+3];
959 for(int a=0;a<h;a+=4) {
960 tmp[a]=X[a]^RM1[a]^IV1[a];
961 tmp[a+1]=X[a+1]^RM1[a+1]^IV1[a+1];
962 tmp[a+2]=X[a+2]^RM1[a+2]^IV1[a+2];
963 tmp[a+3]=X[a+3]^RM1[a+3]^IV1[a+3];
966 for(int a=0;a<h;a+=4) {
967 tmp[a]=Sbox1[tmp[a]];
968 tmp[a+1]=Sbox1[tmp[a+1]];
969 tmp[a+2]=Sbox1[tmp[a+2]];
970 tmp[a+3]=Sbox1[tmp[a+3]];
974 /*for(int a=0;a<h;a+=4) {
975 tmp[a]=Sbox1[X[a]^RM1[a]^IV1[a]];
976 tmp[a+1]=Sbox1[X[a+1]^RM1[a+1]^IV1[a+1]];
977 tmp[a+2]=Sbox1[X[a+2]^RM1[a+2]^IV1[a+2]];
978 tmp[a+3]=Sbox1[X[a+3]^RM1[a+3]^IV1[a+3]];
981 for(int a=0;a<h;a+=4) {
982 fX[a]=Sbox2[tmp[a]^Y[a]];
983 fX[a+1]=Sbox2[tmp[a+1]^Y[a+1]];
984 fX[a+2]=Sbox2[tmp[a+2]^Y[a+2]];
985 fX[a+3]=Sbox2[tmp[a+3]^Y[a+3]];
989 for(int a=0;a<h;a+=4) {
990 fX[a]=Sbox2[Sbox1[X[a]^RM1[a]^IV1[a]]^Y[a]];
991 fX[a+1]=Sbox2[Sbox1[X[a+1]^RM1[a+1]^IV1[a+1]]^Y[a+1]];
992 fX[a+2]=Sbox2[Sbox1[X[a+2]^RM1[a+2]^IV1[a+2]]^Y[a+2]];
993 fX[a+3]=Sbox2[Sbox1[X[a+3]^RM1[a+3]^IV1[a+3]]^Y[a+3]];
997 for(int a=0;a<h;a+=4) {
998 tmp[a]=fX[a]^Y[a]^IV2[a];
999 tmp[a+1]=fX[a+1]^Y[a+1]^IV2[a+1];
1000 tmp[a+2]=fX[a+2]^Y[a+2]^IV2[a+2];
1001 tmp[a+3]=fX[a+3]^Y[a+3]^IV2[a+3];
1005 for(int a=0;a<h;a+=4) {
1006 tmp[a]=Sbox2[tmp[a]];
1007 tmp[a+1]=Sbox2[tmp[a+1]];
1008 tmp[a+2]=Sbox2[tmp[a+2]];
1009 tmp[a+3]=Sbox2[tmp[a+3]];
1014 for(int a=0;a<h;a+=4) {
1015 tmp[a]=Sbox2[fX[a]^Y[a]^IV2[a]];
1016 tmp[a+1]=Sbox2[fX[a+1]^Y[a+1]^IV2[a+1]];
1017 tmp[a+2]=Sbox2[fX[a+2]^Y[a+2]^IV2[a+2]];
1018 tmp[a+3]=Sbox2[fX[a+3]^Y[a+3]^IV2[a+3]];
1023 for(int a=0;a<h;a+=4) {
1024 gY[a]=Sbox1[tmp[a]^RM2[a]];
1025 gY[a+1]=Sbox1[tmp[a+1]^RM2[a+1]];
1026 gY[a+2]=Sbox1[tmp[a+2]^RM2[a+2]];
1027 gY[a+3]=Sbox1[tmp[a+3]^RM2[a+3]];
1034 for(int a=0;a<h;a+=4) {
1035 gY[a]=Sbox1[Sbox2[fX[a]^Y[a]^IV2[a]]^RM2[a]];
1036 gY[a+1]=Sbox1[Sbox2[fX[a+1]^Y[a+1]^IV2[a+1]]^RM2[a+1]];
1037 gY[a+2]=Sbox1[Sbox2[fX[a+2]^Y[a+2]^IV2[a+2]]^RM2[a+2]];
1038 gY[a+3]=Sbox1[Sbox2[fX[a+3]^Y[a+3]^IV2[a+3]]^RM2[a+3]];
1043 for(int a=0;a<h;a+=4) {
1044 seq_out[ind2+a]=gY[a];
1045 seq_out[ind2+a+1]=gY[a+1];
1046 seq_out[ind2+a+2]=gY[a+2];
1047 seq_out[ind2+a+3]=gY[a+3];
1050 for(int a=0;a<h;a+=4) {
1051 seq_out[ind1+a]=fX[a];
1052 seq_out[ind1+a+1]=fX[a+1];
1053 seq_out[ind1+a+2]=fX[a+2];
1054 seq_out[ind1+a+3]=fX[a+3];
1056 for(int a=0;a<h;a+=4) {
1063 for(int a=0;a<h;a+=4) {
1085 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, uint myrand, int debug) {
1097 for(int a=0;a<h;a+=4) {
1104 for(int a=0;a<h;a+=4) {
1106 IV2[a+1]=RM[h*h+a+1];
1107 IV2[a+2]=RM[h*h+a+2];
1108 IV2[a+3]=RM[h*h+a+3];
1114 for(int it=0;it<len/2;it++) {
1115 int ind1=Pbox[it]*h;
1116 int ind2=Pbox[it+len/2]*h;
1119 RM1=&RM[PboxSRM[it]*h];
1120 RM2=&RM[h*h+PboxSRM[it]*h];
1124 for(int a=0;a<h;a+=4) {
1125 gY[a]=seq_in[ind2+a];
1126 gY[a+1]=seq_in[ind2+a+1];
1127 gY[a+2]=seq_in[ind2+a+2];
1128 gY[a+3]=seq_in[ind2+a+3];
1131 for(int a=0;a<h;a+=4) {
1132 fX[a]=seq_in[ind1+a];
1133 fX[a+1]=seq_in[ind1+a+1];
1134 fX[a+2]=seq_in[ind1+a+2];
1135 fX[a+3]=seq_in[ind1+a+3];
1139 for(int a=0;a<h;a+=4) {
1140 tmp[a]=Inv_Sbox1[gY[a]]^RM2[a];
1141 tmp[a+1]=Inv_Sbox1[gY[a+1]]^RM2[a+1];
1142 tmp[a+2]=Inv_Sbox1[gY[a+2]]^RM2[a+2];
1143 tmp[a+3]=Inv_Sbox1[gY[a+3]]^RM2[a+3];
1147 for(int a=0;a<h;a+=4) {
1148 tmp[a]=Inv_Sbox2[tmp[a]];
1149 tmp[a+1]=Inv_Sbox2[tmp[a+1]];
1150 tmp[a+2]=Inv_Sbox2[tmp[a+2]];
1151 tmp[a+3]=Inv_Sbox2[tmp[a+3]];
1156 for(int a=0;a<h;a+=4) {
1157 invgY[a]=tmp[a]^fX[a]^IV2[a];
1158 invgY[a+1]=tmp[a+1]^fX[a+1]^IV2[a+1];
1159 invgY[a+2]=tmp[a+2]^fX[a+2]^IV2[a+2];
1160 invgY[a+3]=tmp[a+3]^fX[a+3]^IV2[a+3];
1164 for(int a=0;a<h;a+=4) {
1165 tmp[a]=Inv_Sbox2[fX[a]]^invgY[a];
1166 tmp[a+1]=Inv_Sbox2[fX[a+1]]^invgY[a+1];
1167 tmp[a+2]=Inv_Sbox2[fX[a+2]]^invgY[a+2];
1168 tmp[a+3]=Inv_Sbox2[fX[a+3]]^invgY[a+3];
1173 for(int a=0;a<h;a+=4) {
1174 tmp[a]=Inv_Sbox1[tmp[a]];
1175 tmp[a+1]=Inv_Sbox1[tmp[a+1]];
1176 tmp[a+2]=Inv_Sbox1[tmp[a+2]];
1177 tmp[a+3]=Inv_Sbox1[tmp[a+3]];
1184 for(int a=0;a<h;a+=4) {
1185 invfX[a]=tmp[a]^RM1[a]^IV1[a];
1186 invfX[a+1]=tmp[a+1]^RM1[a+1]^IV1[a+1];
1187 invfX[a+2]=tmp[a+2]^RM1[a+2]^IV1[a+2];
1188 invfX[a+3]=tmp[a+3]^RM1[a+3]^IV1[a+3];
1193 for(int a=0;a<h;a+=4) {
1194 seq_out[ind2+a]=invfX[a];
1195 seq_out[ind2+a+1]=invfX[a+1];
1196 seq_out[ind2+a+2]=invfX[a+2];
1197 seq_out[ind2+a+3]=invfX[a+3];
1200 for(int a=0;a<h;a+=4) {
1201 seq_out[ind1+a]=invgY[a];
1202 seq_out[ind1+a+1]=invgY[a+1];
1203 seq_out[ind1+a+2]=invgY[a+2];
1204 seq_out[ind1+a+3]=invgY[a+3];
1206 for(int a=0;a<h;a+=4) {
1213 for(int a=0;a<h;a+=4) {
1235 void encrypt_cbc(uchar* seq_in, uchar *seq_out, int len,uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uint myrand, int debug) {
1251 for(int a=0;a<h;a+=4) {
1252 myrand=xorshift32(myrand);
1263 for(int a=0;a<h;a+=4) {
1264 myrand=xorshift32(myrand);
1278 for(int it=0;it<len/2;it++) {
1279 int ind1=Pbox[it]*h;
1280 int ind2=Pbox[it+len/2]*h;
1284 RM1=&RM[PboxSRM[it]*h];
1285 RM2=&RM[h*h+PboxSRM[it]*h];
1288 for(int a=0;a<h;a+=4) {
1289 X[a]=seq_in[ind2+a];
1290 X[a+1]=seq_in[ind2+a+1];
1291 X[a+2]=seq_in[ind2+a+2];
1292 X[a+3]=seq_in[ind2+a+3];
1295 for(int a=0;a<h;a+=4) {
1296 Y[a]=seq_in[ind1+a];
1297 Y[a+1]=seq_in[ind1+a+1];
1298 Y[a+2]=seq_in[ind1+a+2];
1299 Y[a+3]=seq_in[ind1+a+3];
1303 for(int a=0;a<h;a+=4) {
1304 fX[a]=Sbox2[Sbox1[X[a]^RM1[a]^IV1[a]]^Y[a]];
1305 fX[a+1]=Sbox2[Sbox1[X[a+1]^RM1[a+1]^IV1[a+1]]^Y[a+1]];
1306 fX[a+2]=Sbox2[Sbox1[X[a+2]^RM1[a+2]^IV1[a+2]]^Y[a+2]];
1307 fX[a+3]=Sbox2[Sbox1[X[a+3]^RM1[a+3]^IV1[a+3]]^Y[a+3]];
1310 for(int a=0;a<h;a+=4) {
1311 gY[a]=Sbox1[Sbox2[fX[a]^Y[a]^IV2[a]]^RM2[a]];
1312 gY[a+1]=Sbox1[Sbox2[fX[a+1]^Y[a+1]^IV2[a+1]]^RM2[a+1]];
1313 gY[a+2]=Sbox1[Sbox2[fX[a+2]^Y[a+2]^IV2[a+2]]^RM2[a+2]];
1314 gY[a+3]=Sbox1[Sbox2[fX[a+3]^Y[a+3]^IV2[a+3]]^RM2[a+3]];
1318 for(int a=0;a<h;a+=4) {
1319 seq_out[ind2+a]=gY[a];
1320 seq_out[ind2+a+1]=gY[a+1];
1321 seq_out[ind2+a+2]=gY[a+2];
1322 seq_out[ind2+a+3]=gY[a+3];
1325 for(int a=0;a<h;a+=4) {
1326 seq_out[ind1+a]=fX[a];
1327 seq_out[ind1+a+1]=fX[a+1];
1328 seq_out[ind1+a+2]=fX[a+2];
1329 seq_out[ind1+a+3]=fX[a+3];
1331 for(int a=0;a<h;a+=4) {
1338 for(int a=0;a<h;a+=4) {
1360 void decrypt_cbc(uchar* seq_in, uchar *seq_out, int len, uchar* RM, int *Pbox, int *PboxSRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2, uint myrand, int debug) {
1371 for(int a=0;a<h;a+=4) {
1372 myrand=xorshift32(myrand);
1383 for(int a=0;a<h;a+=4) {
1384 myrand=xorshift32(myrand);
1401 for(int it=0;it<len/2;it++) {
1402 int ind1=Pbox[it]*h;
1403 int ind2=Pbox[it+len/2]*h;
1406 RM1=&RM[PboxSRM[it]*h];
1407 RM2=&RM[h*h+PboxSRM[it]*h];
1410 for(int a=0;a<h;a+=4) {
1411 gY[a]=seq_in[ind2+a];
1412 gY[a+1]=seq_in[ind2+a+1];
1413 gY[a+2]=seq_in[ind2+a+2];
1414 gY[a+3]=seq_in[ind2+a+3];
1417 for(int a=0;a<h;a+=4) {
1418 fX[a]=seq_in[ind1+a];
1419 fX[a+1]=seq_in[ind1+a+1];
1420 fX[a+2]=seq_in[ind1+a+2];
1421 fX[a+3]=seq_in[ind1+a+3];
1425 for(int a=0;a<h;a+=4) {
1426 invgY[a]=Inv_Sbox1[gY[a]]^RM2[a];
1427 invgY[a+1]=Inv_Sbox1[gY[a+1]]^RM2[a+1];
1428 invgY[a+2]=Inv_Sbox1[gY[a+2]]^RM2[a+2];
1429 invgY[a+3]=Inv_Sbox1[gY[a+3]]^RM2[a+3];
1433 for(int a=0;a<h;a+=4) {
1434 invgY[a]=Inv_Sbox2[invgY[a]]^fX[a]^IV2[a];
1435 invgY[a+1]=Inv_Sbox2[invgY[a+1]]^fX[a+1]^IV2[a+1];
1436 invgY[a+2]=Inv_Sbox2[invgY[a+2]]^fX[a+2]^IV2[a+2];
1437 invgY[a+3]=Inv_Sbox2[invgY[a+3]]^fX[a+3]^IV2[a+3];
1441 for(int a=0;a<h;a+=4) {
1442 invfX[a]=Inv_Sbox2[fX[a]]^invgY[a];
1443 invfX[a+1]=Inv_Sbox2[fX[a+1]]^invgY[a+1];
1444 invfX[a+2]=Inv_Sbox2[fX[a+2]]^invgY[a+2];
1445 invfX[a+3]=Inv_Sbox2[fX[a+3]]^invgY[a+3];
1449 for(int a=0;a<h;a+=4) {
1450 invfX[a]=Inv_Sbox1[invfX[a]]^RM1[a]^IV1[a];
1451 invfX[a+1]=Inv_Sbox1[invfX[a+1]]^RM1[a+1]^IV1[a+1];
1452 invfX[a+2]=Inv_Sbox1[invfX[a+2]]^RM1[a+2]^IV1[a+2];
1453 invfX[a+3]=Inv_Sbox1[invfX[a+3]]^RM1[a+3]^IV1[a+3];
1458 for(int a=0;a<h;a+=4) {
1459 seq_out[ind2+a]=invfX[a];
1460 seq_out[ind2+a+1]=invfX[a+1];
1461 seq_out[ind2+a+2]=invfX[a+2];
1462 seq_out[ind2+a+3]=invfX[a+3];
1465 for(int a=0;a<h;a+=4) {
1466 seq_out[ind1+a]=invgY[a];
1467 seq_out[ind1+a+1]=invgY[a+1];
1468 seq_out[ind1+a+2]=invgY[a+2];
1469 seq_out[ind1+a+3]=invgY[a+3];
1471 for(int a=0;a<h;a+=4) {
1478 for(int a=0;a<h;a+=4) {
1496 int main(int argc, char** argv) {
1505 for(int i=1; i<argc; i++){
1506 if(strncmp(argv[i],"nb",2)==0) nb_test = atoi(&(argv[i][2])); //nb of test
1507 if(strncmp(argv[i],"cbc",3)==0) cbc=1;
1508 if(strncmp(argv[i],"cbcprng",7)==0) {cbcprng=1;cbc=0;}
1509 if(strncmp(argv[i],"ecb",3)==0) ecb = 1;
1510 if(strncmp(argv[i],"ecbprng",7)==0) {ecbprng=1; ecb=0;}
1511 if(strncmp(argv[i],"h",1)==0) h = atoi(&(argv[i][1])); //size of block
1512 if(strncmp(argv[i],"sizebuf",7)==0) size_buf = atoi(&(argv[i][7])); //SIZE of the buffer
1513 if(strncmp(argv[i],"lena",4)==0) lena = atoi(&(argv[i][4])); //Use Lena or buffer
1516 printf("nb times %d\n",nb_test);
1517 printf("cbc %d\n",cbc);
1518 printf("cbcprng %d\n",cbcprng);
1519 printf("ecb %d\n",ecb);
1521 printf("lena %d\n",lena);
1522 printf("size_buf %d\n",size_buf);
1528 int seed=time(NULL);
1529 // cout<<seed<<endl;
1532 uchar Secretkey[key_size];
1534 uchar counter[key_size];
1536 for(int i=0;i<key_size;i++) {
1537 Secretkey[i]=lrand48()&0xFF;
1538 counter[i]=lrand48()&0xFF;
1551 uchar *data_R, *data_G, *data_B;
1560 load_RGB_pixmap("lena.ppm", &width, &height, &data_R, &data_G, &data_B);
1561 // load_RGB_pixmap("8192.ppm", &width, &height, &data_R, &data_G, &data_B);
1562 imsize=width*height*3;
1563 // load_RGB_pixmap("No_ecb_mode_picture.ppm", &width, &height, &data_R, &data_G, &data_B);
1566 width=height=size_buf;
1567 imsize=width*height;
1568 buffer=new uchar[imsize];
1569 for(int i=0;i<imsize;i++) {
1570 buffer[i]=lrand48();
1578 uchar* seq= new uchar[imsize];
1579 uchar* seq2= new uchar[imsize];
1581 int oneD=width*height;
1583 for(int i=0;i<oneD;i++) {
1585 seq[oneD+i]=data_G[i];
1586 seq[2*oneD+i]=data_B[i];
1590 for(int i=0;i<oneD;i++) {
1599 int total_len=imsize;
1601 int len= total_len/h;
1605 uchar *mix=new uchar[256];
1610 for (int i = 0; i < 256 ; i++) {
1611 mix[i]=Secretkey[i]^counter[i];
1616 sha512 = g_compute_checksum_for_string(G_CHECKSUM_SHA512, (const char*) mix, 256);
1617 // g_print("%s\n", sha512);
1627 // cout<<"hash "<<endl;
1628 for (int i = 0; i < 128 ; i++) {
1635 int *Pbox=new int[len];
1636 int *PboxSRM=new int[len/2];
1637 int *PboxSRM2=new int[len/2];
1640 uchar Inv_Sbox1[256];
1641 uchar Inv_Sbox2[256];
1649 double time_encrypt=0;
1650 double time_decrypt=0;
1653 double t=TimeStart();
1654 rc4key(DK, Sbox1, 8);
1657 rc4key(&DK[8], Sbox2, 8);
1659 rc4key(&DK[16], sc, 16);
1666 rc4keyperm(&DK[72], len, rp, Pbox, 16);
1669 rc4keyperm(&DK[88], len/2, rp, PboxSRM2, 16);
1671 for(int i=0;i<len/2;i++) {
1672 PboxSRM[i]=PboxSRM2[i]&(h-1);
1676 for(int i=0;i<h*2;i++) {
1677 for(int j=0;j<h;j++)
1678 cout<<(int)RM[i*h+j]<<" ";
1685 //time+=TimeStop(t);
1686 //cout<<"Time initializaton "<<time<<endl;
1691 for(int i=0;i<64;i++) {
1702 inverse_tables(Sbox1,256,Inv_Sbox1);
1703 inverse_tables(Sbox2,256,Inv_Sbox2);
1707 lehmer64_seed(myrand);
1714 for(i=0;i<nb_test;i++)
1717 encrypt_cbc_prng<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1719 encrypt_cbc_rm<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1721 encrypt_ecb<4>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1725 for(i=0;i<nb_test;i++)
1728 encrypt_cbc_prng<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1730 encrypt_cbc_rm<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1732 encrypt_ecb<8>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1736 for(i=0;i<nb_test;i++)
1739 encrypt_cbc_prng<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1741 encrypt_cbc_rm<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1743 encrypt_ecb<16>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1747 for(i=0;i<nb_test;i++)
1750 encrypt_cbc_prng<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1752 encrypt_cbc_rm<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1754 encrypt_ecb<32>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1758 for(i=0;i<nb_test;i++)
1761 encrypt_cbc_prng<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1763 encrypt_cbc_rm<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1765 encrypt_ecb<64>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1770 for(i=0;i<nb_test;i++)
1773 encrypt_cbc_prng<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1775 encrypt_cbc_rm<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1777 encrypt_ecb<128>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1782 for(i=0;i<nb_test;i++)
1785 encrypt_cbc_prng<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1787 encrypt_cbc_rm<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1789 encrypt_ecb<256>(seq, seq2,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,myrand,0);
1794 time_encrypt+=TimeStop(t);
1795 //cout<<"Time encrypt "<<
1796 cout<<(double)imsize*nb_test/time_encrypt<<"\t";
1800 for(int i=0;i<oneD;i++) {
1802 data_G[i]=seq2[oneD+i];
1803 data_B[i]=seq2[2*oneD+i];
1805 store_RGB_pixmap("lena2.ppm", data_R, data_G, data_B, width, height);
1809 lehmer64_seed(myrand);
1814 for(i=0;i<nb_test;i++) {
1816 decrypt_cbc_prng<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1818 decrypt_cbc_rm<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1820 decrypt_ecb<4>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1824 for(i=0;i<nb_test;i++) {
1826 decrypt_cbc_prng<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1828 decrypt_cbc_rm<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1830 decrypt_ecb<8>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1834 for(i=0;i<nb_test;i++) {
1836 decrypt_cbc_prng<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1838 decrypt_cbc_rm<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1840 decrypt_ecb<16>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1844 for(i=0;i<nb_test;i++) {
1846 decrypt_cbc_prng<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1848 decrypt_ecb<32>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1852 for(i=0;i<nb_test;i++) {
1854 decrypt_cbc_prng<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1856 decrypt_cbc_rm<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1858 decrypt_ecb<64>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1862 for(i=0;i<nb_test;i++) {
1864 decrypt_cbc_prng<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1866 decrypt_cbc_rm<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1868 decrypt_ecb<128>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1872 for(i=0;i<nb_test;i++) {
1874 decrypt_cbc_prng<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1876 decrypt_cbc_rm<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1878 decrypt_ecb<256>(seq2,seq,len,RM,Pbox,PboxSRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0);
1883 time_decrypt+=TimeStop(t);
1884 //cout<<"Time decrypt "
1885 cout<<(double)imsize*nb_test/time_decrypt<<"\t";
1888 for(int i=0;i<oneD;i++) {
1890 data_G[i]=seq[oneD+i];
1891 data_B[i]=seq[2*oneD+i];
1893 store_RGB_pixmap("lena3.ppm", data_R, data_G, data_B, width, height);
1897 for(int i=0;i<imsize;i++) {
1898 //cout<<(int)buffer[i]<<endl;
1899 if(buffer[i]!=seq[i]) {
1903 // cout<<"RESULT CORRECT: "<<equal<<endl;