-rwxr-xr-x 4068 cryptattacktester-20231020/isdpredict-table.py raw
#!/usr/bin/env python3
import sys
def problem_format(P):
N = None
W = None
for x in P.split(','):
x = x.split('=')
if x[0] == 'N':
N = int(x[1])
return '$%d$' % N
constraint_titles = (
( 'isd', r'\hbox{\verb|isd|}' ),
( 'RE', r'\hbox{\verb|RE|}' ),
( 'L', r'\ell' ),
( 'P', "p"),
( 'PI', "p'" ),
( 'PIJ', "p''" ),
( 'C', 'C' ),
)
knownconstraints = 'attack','RE','L','P','PI','PIJ','CP','CS','FW'
def attack_fci(A):
result = ''
category = ''
CP,CS = None,None
attack,PIJ,PI = None,None,None
interesting = True
constraints = {}
for x in A.split(','):
x = x.split('=')
assert x[0] in knownconstraints
constraints[x[0]] = x[1]
category = ['attack='+constraints['attack']]
assert constraints['attack'].startswith('isd')
constraints['isd'] = constraints['attack'][3:]
if 'PIJ' in constraints and 'PI' in constraints:
PIJ = int(constraints['PIJ'])
PI = int(constraints['PI'])
category += ['mmt=%s'%(PIJ*2==PI)]
if 'CP' in constraints and 'CS' in constraints:
CP = int(constraints['CP'])
CS = int(constraints['CS'])
C = {(1,0):0,(0,1):1,(0,0):2}[CP,CS]
constraints['C'] = C
category += [f"C={C}"]
result = '&'.join(str(constraints.get(c,'')) for c,t in constraint_titles)
PL = {'0':'P','1':'PI','2':'PIJ'}[constraints['isd']]
PL = int(constraints[PL])
if 'RE' in constraints and PL > 2: interesting = False
if constraints['isd'] == '0' and PL > 3: interesting = False
if constraints['isd'] == '1' and PL > 9: interesting = False
if constraints['isd'] == '2' and C == 0 and PI == 2*PIJ and PL > 9: interesting = False
category = ','.join(category)
if A == 'attack=isd0,P=0,L=0,FW=1,RE=1': category = 'prange'
return result,category,interesting
def attack_format(A): return attack_fci(A)[0]
def attack_category(A): return attack_fci(A)[1]
def attack_interesting(A): return attack_fci(A)[2]
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
problems = []
categories = []
attacks = []
data = {}
for line in sys.stdin:
line = line.split()
P = line[0]
A = line[1]
assert line[2] == 'searchparams'
assert line[3] == 'problem=uniformmatrix'
Q = line[6]
assert line[7] == 'lgratio'
lgratio = intervalparse(line[8])
assert '|' not in P
if P == 'N=6960,W=119':
# save space in table
# 6960 is almost identical to 6688, marginally higher
continue
if P == 'N=1347,W=25':
continue
if not attack_interesting(A): continue
if P not in problems: problems += [P]
if 'RE=1' in Q.split(','):
ARE = A+',RE=1'
if attack_interesting(ARE):
C = attack_category(ARE)
if C not in categories: categories += [C]
if ARE not in attacks: attacks += [ARE]
assert (P,ARE) not in data
data[P,ARE] = lgratio
if A not in attacks: attacks += [A]
C = attack_category(A)
if C not in categories: categories += [C]
key = P,A
if key not in data:
data[key] = lgratio
data[key] = min(data[key],lgratio)
print(r'\begin{tabular}{%s|%s}' % ('r'*len(constraint_titles),'r'*len(problems)))
print('&'.join('$%s$'%t for c,t in constraint_titles)+''.join('&'+problem_format(P) for P in problems)+r'\\')
print(r'\hline')
for C in categories:
best = {}
for A in attacks:
if attack_category(A) != C: continue
for P in problems:
key = P,A
if key not in data: continue
if P not in best: best[P] = data[key]
best[P] = min(best[P],data[key])
for A in attacks:
row = ''
row += attack_format(A)
if attack_category(A) != C: continue
for P in problems:
key = P,A
if key in data:
entry = '%.2f'%data[key]
if data[key] == best[P]:
row += r'&\color{blue}%s'%entry
else:
row += '&%s'%entry
else:
row += '&'
print(row+r'\\')
print(r'\hline')
print(r'\end{tabular}')