X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/blobdiff_plain/a2a985ff223e108bdc73b0ade26f5c1eb970acf0..5ba1e7ac73522b93e31fe7be8d11505ab1a7794c:/Arduino/sketch_One_Round/sketch_One_Round.ino diff --git a/Arduino/sketch_One_Round/sketch_One_Round.ino b/Arduino/sketch_One_Round/sketch_One_Round.ino index 503d3f3..69ec9c2 100644 --- a/Arduino/sketch_One_Round/sketch_One_Round.ino +++ b/Arduino/sketch_One_Round/sketch_One_Round.ino @@ -1,11 +1,11 @@ -#include + #include //#include "./printf.h" //#include -const int size_mesg=256; +const int size_mesg=16; @@ -13,7 +13,7 @@ const int size_mesg=256; const int sleepTimeS = 10; -const int h=4; +const int h=2; const int h2=h*h; byte DK[64]; int rp=1; @@ -23,6 +23,7 @@ const int len=size_mesg/h2; typedef byte uchar; +typedef unsigned int uint; int Pbox[len]; int PboxRM[h2]; @@ -30,13 +31,42 @@ int Pbox[len]; uchar Sbox2[256]; uchar RM1_cpy[h2]; + +struct ulong2{ + unsigned long int x, y; +}; + +typedef struct ulong2 ulong2; +typedef unsigned long int ulong; +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; +} +uint pcg32_random_r(ulong2* rng) +{ + // pcg32_random_t *rng=(pcg32_random_t*)rng2; + ulong oldstate = rng->x; + // Advance internal state + rng->x = oldstate * 6364136223846793005ULL + (rng->y|1); + // Calculate output function (XSH RR), uses old state for max ILP + uint xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u; + uint rot = oldstate >> 59u; + return (xorshifted >> rot) | (xorshifted << ((-rot) & 31)); +} + + void inverse_tables(uchar *tab, int size_tab,uchar *inv_perm_tabs) { @@ -122,7 +152,7 @@ void encrypt_ctr(const uchar* seq_in, uchar *seq_out, int len,uchar* RM1,const i for(int a=0;a