-rwxr-xr-x 1363 cryptattacktester-20231020/isdpredict2.py raw
#!/usr/bin/env python3 import sys import subprocess import multiprocessing todo = [] for line in sys.stdin: line = line.split() Pconstraint = line[0] Aconstraint = line[1] assert line[2] == 'searchparams' assert line[3] == 'problem=uniformmatrix' P = line[4] A = line[5] Q = line[6] Q = Q.split(',') assert Q[:4] == ['I=1','RE=1','X=1','YX=1'] Q = tuple(Q[4:]) for lgreset in range(25): todo += [(Pconstraint,Aconstraint,P,A,Q,lgreset)] def handle(task): Pconstraint,Aconstraint,P,A,Q,lgreset = task reset = 1<<lgreset iters = reset<<16 Q = list(Q) Q += ['I=%d'%iters,'RE=%d'%reset] Q = ','.join(Q) searchparams = subprocess.run(['./searchparams','problem=uniformmatrix',P,A,Q],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[:2]+(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()