--- /dev/null
+//gcc pixmap_io.c -c
+//g++ -O3 one_round_new.cpp pixmap_io.o -o one_round_new -std=c++11
+
+#include <iostream>
+#include <list>
+#include<math.h>
+#include<stdlib.h>
+#include<stdio.h>
+#include<string.h>
+#include <fstream>
+#include <sys/time.h>
+
+using namespace std;
+
+
+int key_size=256;
+int nb_test=1;
+int cbcprng=0;
+int cbcrm=0;
+int ecbrm=0;
+int ecbprng=0;
+
+
+
+typedef __uint64_t mylong;
+
+
+typedef unsigned char uchar;
+
+
+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);
+}
+
+
+
+
+uint xorshift32(const uint t)
+{
+ /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
+ uint x = t;
+ x ^= x << 13;
+ x ^= x >> 17;
+ x ^= x << 5;
+ return x;
+}
+
+
+mylong xorseed;
+
+mylong xorshift64()
+{
+ /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
+ mylong x = xorseed;
+ x ^= x >> 12; // a
+ x ^= x << 25; // b
+ x ^= x >> 27; // c
+
+
+ return xorseed=x;
+}
+
+/*
+__uint128_t g_lehmer64_state;
+
+inline uint64_t splitmix64_stateless(uint64_t index) {
+ uint64_t z = (index + UINT64_C(0x9E3779B97F4A7C15));
+ z = (z ^ (z >> 30)) * UINT64_C(0xBF58476D1CE4E5B9);
+ z = (z ^ (z >> 27)) * UINT64_C(0x94D049BB133111EB);
+ return z ^ (z >> 31);
+}
+
+
+inline void lehmer64_seed(uint64_t seed) {
+ g_lehmer64_state = (((__uint128_t)splitmix64_stateless(seed)) << 64) +
+ splitmix64_stateless(seed + 1);
+}
+
+inline uint64_t lehmer64() {
+ g_lehmer64_state *= UINT64_C(0xda942042e4dd58b5);
+ ;
+ return g_lehmer64_state >> 64;
+}
+
+*/
+
+
+
+void inverse_tables(uchar *tab, int size_tab,uchar *inv_perm_tabs) {
+
+ for(int i=0;i<size_tab;i++) {
+ inv_perm_tabs[tab[i]] = i;
+ }
+
+}
+
+void inverse_tables_int(int *tab, int size_tab,int *inv_perm_tabs) {
+
+ for(int i=0;i<size_tab;i++) {
+ inv_perm_tabs[tab[i]] = i;
+ }
+
+}
+
+
+
+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;
+ }
+}
+
+
+
+void rc4keyperm(uchar *key,int len, int rp,int *sc, int size_DK) {
+
+ //sc=1:len;
+
+
+
+ for (int i=0;i<len;i++) {
+ sc[i]=i;
+ }
+ for (int it = 0; it < rp; it++) {
+ int j0 = 1;
+ for(int i0 = 0; i0<len; i0++) {
+ j0 = (j0 + sc[i0] + sc[j0] + key[i0%size_DK] )% len;
+ int tmp = sc[i0];
+ sc[i0] = sc[j0];
+ sc[j0] = tmp;
+ }
+
+ }
+}
+
+void prga(uchar *sc, int ldata, uchar *r) {
+ uchar i0=0;
+ uchar j0=0;
+
+ for (int it=0; it<ldata; it++) {
+ i0 = ((i0+1)%255);
+ j0 = (j0 + sc[i0])&0xFF;
+ uchar tmp = sc[i0];
+ sc[i0] = sc[j0];
+ sc[j0] = tmp;
+ r[it]=sc[(sc[i0]+sc[j0])&0xFF];
+ }
+}
+
+
+
+
+
+
+
+
+int main(int argc, char** argv) {
+
+ int nb_test=100000;
+
+ int seed=time(NULL);
+
+ srand48(seed);
+
+ uchar Secretkey[key_size];
+
+ uchar counter[key_size];
+
+
+ int size = 128;
+ uchar DK[size];
+
+ for(int i=0;i<key_size;i++) {
+ DK[i]=lrand48()&0xFF;
+ }
+
+
+
+
+
+
+
+
+
+
+ uchar Sbox1[256];
+ uchar Sbox2[256];
+ uchar Temp[256];
+
+
+
+ double time=0;
+
+
+ rc4key(DK, Sbox1, 8);
+
+
+ rc4key(&DK[8], Sbox2, 8);
+
+ double t=TimeStart();
+
+
+
+ for(int nb=0;nb<nb_test;nb++) {
+
+ for(int i=0;i<256;i++) {
+ Temp[i]=Sbox1[i];
+ }
+
+ for(int i=0;i<256;i++) {
+ Sbox1[i]=Sbox1[Sbox2[i]];
+ }
+
+ for(int i=0;i<256;i++) {
+ Sbox2[i]=Sbox2[Temp[i]];
+ }
+
+
+ }
+
+ time+=TimeStop(t);
+ cout<<"Time sub nb times "<<nb_test<<" = "<<time<<endl;
+
+
+
+ return 0;
+}