-rwxr-xr-x 2282 cryptattacktester-20230614/aes128-table.py raw
#!/usr/bin/env python3
import sys
from math import log
def intervalparse(x):
assert x.startswith('[')
assert x.endswith(']')
x = x[1:-1]
x = x.split(',')
assert len(x) == 2
x0,x1 = map(float,x)
assert x0 > 0
assert x1 >= x0
assert x1 < x0*1.0001 # indistinguishable on graph
return x0
iter = {}
cost = {}
lgcost = {}
prob = {}
prob2 = {}
trials = {}
succ = {}
QX = {}
QU = {}
QF = {}
for line in sys.stdin:
line = line.split()
assert line[1] == 'problem=aes128'
assert line[3] == 'attack=aes128_enum'
data = {}
for x in line[2].split(',')+line[4].split(','):
y = x.split('=')
assert len(y) == 2
assert y[0] not in data
data[y[0]] = int(y[1])
K,C,I = data['K'],data['C'],data['I']
assert I+1 == 2**K
iter[K,C] = I
QX[K,C],QU[K,C],QF[K,C] = data['QX'],data['QU'],data['QF']
if line[0] == 'searchparams':
assert (K,C) not in cost
assert (K,C) not in prob
assert line[7] == 'cost'
cost[K,C] = int(line[8])
assert line[9] == 'lgcost'
lgcost[K,C] = intervalparse(line[10])
assert line[11] == 'prob'
prob[K,C] = intervalparse(line[12])
if line[0] == 'circuitcost':
assert line[5] == 'prediction'
assert int(line[6]) == cost[K,C]
assert line[7] == 'ops'
assert int(line[8]) == cost[K,C]
assert 'ALERT' not in line
if line[0] == 'circuitprob':
assert (K,C) not in prob2
assert (K,C) not in succ
assert line[5] == 'cost'
assert int(line[6]) == cost[K,C]
assert line[7] == 'prob'
assert intervalparse(line[8]) == prob[K,C]
assert line[9] == 'prob2'
prob2[K,C] = intervalparse(line[10])
assert line[11] == 'trials'
trials[K,C] = int(line[12])
assert line[15] == 'succ'
succ[K,C] = intervalparse(line[16])
print(r'\begin{tabular}{rr|rrrrrrr}')
print(r'$K$&$C$&\verb|QX|&\verb|QU|&\verb|QF|&lgcost&prob&prob2&succ\\')
print(r'\noalign{\hrule}')
for K,C in iter:
if K > 16 and K%16: continue
costperiter = '%.6f'%(log(cost[K,C])/log(2.0))
if (K,C) in trials:
assert trials[K,C] == 100000
p = '%.5f'%prob[K,C]
p2 = '%.5f'%prob2[K,C] if (K,C) in prob2 else ''
s = '%.5f'%succ[K,C] if (K,C) in succ else ''
print(fr'{K}&{C}&{QX[K,C]}&{QU[K,C]}&{QF[K,C]}&{costperiter}&{p}&{p2}&{s}\\')
print(r'\end{tabular}')