Skip to content

Instantly share code, notes, and snippets.

@kuboon
Last active September 6, 2023 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuboon/60877c42adcc654efdf9fa049ca02265 to your computer and use it in GitHub Desktop.
Save kuboon/60877c42adcc654efdf9fa049ca02265 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define N 16
#define M 16
#define NN 2
unsigned char x0[N]={0};
unsigned char x1[N]={0};
unsigned char x2[N]={0};
void rp(unsigned char* a) {
int i, j, x;
for (i = 0; i < N; i++) {
a[i] = i;
}
for (i = 0; i < N - 2; i++) {
// rand from i+1 to N-1
j = (rand() % (N - 1 - i)) + i + 1;
// swap a[i] and a[j]
x = a[j];
a[j] = a[i];
a[i] = x;
}
if (a[N - 1] == N - 1) {
a[N - 1] = a[N - 2];
a[N - 2] = N - 1;
}
}
void data(fp){
unsigned long long int i,j=0,k=0;
unsigned char a[N]={1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0};
unsigned short aa=0;
unsigned char z[N];
unsigned char w[N];
unsigned char ww[N]={0};
for(i=0;i<N;i++)
x2[x0[i]]=i;
while(j<137438953){
for(i=0;i<N;i++)
ww[i]=a[x1[i]];
for(i=0;i<N;i++)
a[i]^=ww[i];
for(cnt=0;cnt<NN;cnt++){
for(i=cnt*8;i<8*cnt+8;i++){
aa=aa<<1;
aa^=a[i];
}
}
fwrite(&aa,NN,1,fp);
for(i=0;i<N;i++)
w[i]=x0[x1[x2[i]]];
for(i=0;i<N;i++){
x1[i]=w[i];
}
j++;
}
}
int main(){
FILE *fp
time_t t;
srand(clock()+time(&t));
rp(x0);
rp(x1);
fp = fopen("rand.dat","wb");
data(fp);
fclose(fp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment