Last active
September 6, 2023 04:46
-
-
Save kuboon/0b6bfb15c7c3b9989efd5f323ab2ff5c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <time.h> | |
#include <stdlib.h> | |
#define N 16 | |
#define M 16 | |
#define NN 2 | |
unsigned char xx[N]; | |
unsigned char x0[M]={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(){ | |
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]; | |
FILE *fp; | |
unsigned char ww[N]={0}; | |
fp=fopen("rand.dat","wb"); | |
for(i=0;i<N;i++) | |
x2[x0[i]]=i; | |
while(j<137438953){ | |
for(i=0;i<N;i++) | |
a[i]^=a[x1[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++; | |
} | |
fclose(fp); | |
} | |
int main(){ | |
time_t t; | |
srand(clock()+time(&t)); | |
rp(x0); | |
rp(x1); | |
data(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment