-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_function.c
More file actions
54 lines (50 loc) · 1.1 KB
/
generate_function.c
File metadata and controls
54 lines (50 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*This script is used to generate random n-bit
* functions where 'n' is user provided and writes
* the truth table in an external file named
* data.txt which could be used in the nonlinearity
* estimation program.*/
#include<stdio.h>
#include<math.h>
#include<time.h>
#include<stdlib.h>
/*struct Data
{
long long int
};
*/
long long int int_to_bin(long long int k){
if (k == 0) return 0;
if (k == 1) return 1;
return (k % 2) + 10 * int_to_bin(k / 2);
}
int bent(long long int k){
int r=0, r1=0,r2=0;
while(k){
r1 = k%10;
r2 = (k/10)%10;
r += r1*r2;
k = k/100;
}
return r%2;
}
int main(){
int n, cond, r;
time_t t;
srand((unsigned) time(&t));
FILE *file;
file = fopen("data.txt", "w+");
printf("Enter the number of bits of the function : ");
scanf("%d", &n);
fprintf(file,"%d\n",n);
printf("Please enter 1 if you would like it to be a bent function, else enter 0 : ");
scanf("%d", &cond);
for(int i=0; i<pow(2,n); i++){
int i_b = int_to_bin(i);
if(cond)
r = bent(i_b);
else
r = rand()%2;
fprintf(file, "%0*lld\t%d\n", n, int_to_bin(i), r);
}
fclose(file);
}