-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcorr.c
96 lines (89 loc) · 2.01 KB
/
corr.c
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
double t[16][256];
double tdev[16][256];
double u[16][256];
double udev[16][256];
void readdata(void)
{
int lines;
int b;
int size;
int j;
long long packets;
double cycles;
double deviation;
double aboveaverage;
double avdev;
for (lines = 0;lines < 8192;++lines) {
if (scanf("%d%d%d%lld%lf%lf%lf%lf"
,&b
,&size
,&j
,&packets
,&cycles
,&deviation
,&aboveaverage
,&avdev
) != 8) exit(100);
b &= 15;
j &= 255;
if (lines < 4096) {
t[b][j] = aboveaverage;
tdev[b][j] = avdev;
} else {
u[b][j] = aboveaverage;
udev[b][j] = avdev;
}
}
}
double c[256];
double v[256];
int cpos[256];
int cposcmp(const void *v1,const void *v2)
{
int *i1 = (int *) v1;
int *i2 = (int *) v2;
if (c[255 & *i1] < c[255 & *i2]) return 1;
if (c[255 & *i1] > c[255 & *i2]) return -1;
return 0;
}
void processdata(void)
{
int b;
int i;
int j;
int numok;
double z;
FILE *fp = fopen("/data/local/tmp/correlation.txt", "w+");
for (b = 0;b < 16;++b) {
for (i = 0;i < 256;++i) {
c[i] = v[i] = 0;
cpos[i] = i;
for (j = 0;j < 256;++j) {
c[i] += t[b][j] * u[b][i ^ j]; //correlation
z = tdev[b][j] * u[b][i ^ j];
v[i] += z * z;
z = t[b][j] * udev[b][i ^ j];
v[i] += z * z;
}
}
qsort(cpos,256,sizeof(int),cposcmp);
numok = 0;
for (i = 0;i < 256;++i)
if (c[cpos[0]] - c[cpos[i]] < 10 * sqrt(v[cpos[i]]))
++numok;
printf("%3d %2d ",numok,b);
for (i = 0;i < 256;++i)
if (c[cpos[0]] - c[cpos[i]] < 10 * sqrt(v[cpos[i]]))
printf(" %02x",cpos[i]);
printf("\n");
}
}
int main()
{
readdata();
processdata();
return 0;
}