-rwxr-xr-x 3433 cryptattacktester-20231020/isdpredict1.py raw
#!/usr/bin/env python3
import sys
import subprocess
import multiprocessing
problems = (
'N=1284,W=24',
'N=1347,W=25',
'N=3488,W=64',
'N=4608,W=96',
'N=6688,W=128',
'N=6960,W=119',
'N=8192,W=128',
)
attacks = (
'attack=isd0,P=0,L=0,FW=1',
'attack=isd0,P=1,L=0,FW=1',
'attack=isd0,P=2,L=0,FW=1',
'attack=isd0,P=3,L=0,FW=1',
'attack=isd0,P=4,L=0,FW=1',
'attack=isd0,P=1,FW=1',
'attack=isd0,P=2,FW=1',
'attack=isd0,P=3,FW=1',
'attack=isd0,P=4,FW=1',
'attack=isd1,PI=1,FW=1',
'attack=isd1,PI=2,FW=1',
'attack=isd1,PI=3,FW=1',
'attack=isd1,PI=4,FW=1',
'attack=isd1,PI=5,FW=1',
'attack=isd1,PI=6,FW=1',
'attack=isd1,PI=7,FW=1',
'attack=isd1,PI=8,FW=1',
'attack=isd1,PI=9,FW=1',
'attack=isd1,PI=10,FW=1',
'attack=isd1,PI=11,FW=1',
'attack=isd1,PI=12,FW=1',
'attack=isd2,PI=2,PIJ=1,CP=1,CS=0,FW=1',
'attack=isd2,PI=4,PIJ=2,CP=1,CS=0,FW=1',
'attack=isd2,PI=6,PIJ=3,CP=1,CS=0,FW=1',
'attack=isd2,PI=8,PIJ=4,CP=1,CS=0,FW=1',
'attack=isd2,PI=10,PIJ=5,CP=1,CS=0,FW=1',
'attack=isd2,PI=12,PIJ=6,CP=1,CS=0,FW=1',
'attack=isd2,PI=14,PIJ=7,CP=1,CS=0,FW=1',
'attack=isd2,PI=16,PIJ=8,CP=1,CS=0,FW=1',
'attack=isd2,PI=18,PIJ=9,CP=1,CS=0,FW=1',
'attack=isd2,PI=20,PIJ=10,CP=1,CS=0,FW=1',
'attack=isd2,PI=22,PIJ=11,CP=1,CS=0,FW=1',
'attack=isd2,PI=24,PIJ=12,CP=1,CS=0,FW=1',
'attack=isd2,PI=2,PIJ=2,CP=1,CS=0,FW=1',
'attack=isd2,PI=4,PIJ=3,CP=1,CS=0,FW=1',
'attack=isd2,PI=6,PIJ=4,CP=1,CS=0,FW=1',
'attack=isd2,PI=8,PIJ=5,CP=1,CS=0,FW=1',
'attack=isd2,PI=10,PIJ=6,CP=1,CS=0,FW=1',
'attack=isd2,PI=12,PIJ=7,CP=1,CS=0,FW=1',
'attack=isd2,PI=14,PIJ=8,CP=1,CS=0,FW=1',
'attack=isd2,PI=16,PIJ=9,CP=1,CS=0,FW=1',
'attack=isd2,PI=18,PIJ=10,CP=1,CS=0,FW=1',
'attack=isd2,PI=20,PIJ=11,CP=1,CS=0,FW=1',
'attack=isd2,PI=22,PIJ=12,CP=1,CS=0,FW=1',
'attack=isd2,PI=2,PIJ=1,CP=0,CS=1,FW=1',
'attack=isd2,PI=4,PIJ=2,CP=0,CS=1,FW=1',
'attack=isd2,PI=6,PIJ=3,CP=0,CS=1,FW=1',
'attack=isd2,PI=8,PIJ=4,CP=0,CS=1,FW=1',
'attack=isd2,PI=10,PIJ=5,CP=0,CS=1,FW=1',
'attack=isd2,PI=12,PIJ=6,CP=0,CS=1,FW=1',
'attack=isd2,PI=14,PIJ=7,CP=0,CS=1,FW=1',
'attack=isd2,PI=16,PIJ=8,CP=0,CS=1,FW=1',
'attack=isd2,PI=18,PIJ=9,CP=0,CS=1,FW=1',
'attack=isd2,PI=20,PIJ=10,CP=0,CS=1,FW=1',
'attack=isd2,PI=22,PIJ=11,CP=0,CS=1,FW=1',
'attack=isd2,PI=24,PIJ=12,CP=0,CS=1,FW=1',
'attack=isd2,PI=26,PIJ=13,CP=0,CS=1,FW=1',
'attack=isd2,PI=28,PIJ=14,CP=0,CS=1,FW=1',
'attack=isd2,PI=30,PIJ=15,CP=0,CS=1,FW=1',
'attack=isd2,PI=32,PIJ=16,CP=0,CS=1,FW=1',
'attack=isd2,PI=34,PIJ=17,CP=0,CS=1,FW=1',
'attack=isd2,PI=36,PIJ=18,CP=0,CS=1,FW=1',
)
todo = [(P,A) for A in attacks for P in problems]
def handle(task):
P,A = task
searchparams = subprocess.run(['./searchparams','problem=uniformmatrix',P,A,'I=1,RE=1,X=1,YX=1'],capture_output=True,universal_newlines=True,check=True)
searchparams = searchparams.stdout
if len(searchparams) == 0:
return task,None
return task,searchparams.splitlines()[-1]
results = {}
printpos = 0
def maybeprint():
global printpos
while printpos < len(todo):
task = todo[printpos]
if task not in results: break
result = results[task]
if result is not None:
print('%s %s %s' % (task+(result,)))
sys.stdout.flush()
printpos += 1
with multiprocessing.Pool() as p:
for task,result in p.imap_unordered(handle,reversed(todo),chunksize=1):
results[task] = result
maybeprint()