summaryrefslogtreecommitdiff
path: root/analyze.py
blob: 75d8686612e1cc84bd26004894c8109cfdf9bf55 (plain)
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
import gmpy, numpy, scipy.misc, sys
import matplotlib.pyplot as plot

input_file = file(sys.argv[1])

ideal_hash_diffusion = [int(scipy.misc.comb(160, n)) for n in range(0, 161)]
hash_diffusion = [0] * 161
ideal_deal_diffusion = [int(scipy.misc.comb(96, n)) for n in range(0, 97)]
deal_diffusion = [0] * 97

prev_seed = None
prev_output = 0
prev_deal = 0

for line in input_file:
    bits = line.split()
    output = int(bits[1], 16)
    seed = bits[0][8:48]
    deal = output & 0xFFFFFFFFFFFFFFFFFFFFFFFF0000000000000000
    if seed == prev_seed:
        results = [output ^ prev_output, deal ^ prev_deal]
        results += [gmpy.popcount(l) for l in results]
        hash_diffusion[results[2]] += 1
        deal_diffusion[results[3]] += 1
        print '%040x %040x %3d %3d' % tuple(results)
    prev_output = output
    prev_deal = deal
    prev_seed = seed

ideal_hash_diffusion_normalized = [float(n)/sum(ideal_hash_diffusion) for n in ideal_hash_diffusion]
hash_diffusion_normalized = [float(n)/sum(hash_diffusion) for n in hash_diffusion]
ideal_deal_diffusion_normalized = [float(n)/sum(ideal_deal_diffusion) for n in ideal_deal_diffusion]
deal_diffusion_normalized = [float(n)/sum(deal_diffusion) for n in deal_diffusion]

figure = plot.figure(figsize=(20,20))
hash_plot = figure.add_subplot(211, title='Full hash diffusion')
hash_plot.plot(ideal_hash_diffusion_normalized)
hash_plot.plot(hash_diffusion_normalized)
hash_plot.legend(['Ideal', 'Actual'])
deal_plot = figure.add_subplot(212, title='96-bit deal diffusion')
deal_plot.plot(ideal_deal_diffusion_normalized)
deal_plot.plot(deal_diffusion_normalized)
deal_plot.legend(['Ideal', 'Actual'])
figure.savefig(sys.argv[1] + '.png')