Cryptography Reference
In-Depth Information
81
{
fprintf(stderr, "no period found! \ n");
82
83
exit(1);
84
}
85
/* compute characters of key */
86
key[period] = ' \ 0';
87
Np = (N/period-1)*period;
88
trust = 1.e+9;
89
for(off=period; off--;)
90
{
91
y
memset(cnt, 0, 256*sizeof(int));
92
/* compute distribution */
93
for(n = Np + off; n >= 0; n -= period) ++cnt[buf[n]];
94
for(n=256; n--;) frequ[n] = cnt[n]/Nd;
95
/* align distribution: get 1 char of key */
96
min = 257.;
97
for(m = 256; m--;)
98
{
99
if(frequ[indx^m] < thresh) continue;
100
delta = 0.;
101
for(n = 256; n--;)
102
delta += (frequ[n^m] -
patt[n])*(frequ[n^m] - patt[n]);
103
if(min > delta)
104
{
105
trust1 = min/delta;
Figure 3.13: ( continued )
Search WWH ::




Custom Search