2006-11-21 13:40:50 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Idea:
|
|
|
|
#
|
|
|
|
# We test all variants [0..31] until we are sure they work. Thus,
|
|
|
|
# we slowly refine the tests.
|
|
|
|
#
|
2020-10-27 21:09:03 +00:00
|
|
|
import subprocess
|
2006-11-21 13:40:50 +00:00
|
|
|
|
|
|
|
def startset():
|
2020-10-27 21:09:03 +00:00
|
|
|
return list(range(0,32))
|
2006-11-21 13:40:50 +00:00
|
|
|
|
|
|
|
mainlist = [11, 15]
|
2020-10-27 21:09:03 +00:00
|
|
|
print("Starting with", mainlist)
|
2006-11-21 13:40:50 +00:00
|
|
|
return mainlist
|
|
|
|
|
|
|
|
def tuplingchoice(variant,P,runs,latupling):
|
|
|
|
# variant is in range [0..64>,
|
|
|
|
# where we use the highest bid to signify the
|
|
|
|
# associativity of the tupling.
|
|
|
|
|
|
|
|
extraflags = ""
|
|
|
|
if latupling:
|
|
|
|
extraflags += " --la-tupling"
|
|
|
|
|
|
|
|
s = "./multinsl-generator.py"
|
|
|
|
s += " %i %s" % (P,variant)
|
|
|
|
s += " | scyther -r%i --untyped %s" % (runs, extraflags)
|
|
|
|
#s += " | scyther -a -r%i --summary" % runs
|
|
|
|
#print s
|
|
|
|
s += " | grep \"Fail\""
|
2020-10-27 21:09:03 +00:00
|
|
|
out = subprocess.getoutput(s)
|
2006-11-21 13:40:50 +00:00
|
|
|
if out == "":
|
|
|
|
#print "Okay"
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
#print out
|
|
|
|
# Thus, MultiNSL P variant has the first attack for n runs
|
|
|
|
return False
|
|
|
|
|
|
|
|
def testvariant(v,p,r):
|
|
|
|
if not tuplingchoice (v,p,r, False):
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return tuplingchoice (v,p,r, True)
|
|
|
|
|
|
|
|
def removeattacks (testlist, P, runs):
|
|
|
|
okaylist = []
|
|
|
|
for v in testlist:
|
|
|
|
if testvariant (v, P, runs):
|
|
|
|
okaylist.append(v)
|
|
|
|
return okaylist
|
|
|
|
|
|
|
|
def scan(testlist, P, runs):
|
2020-10-27 21:09:03 +00:00
|
|
|
print("Testing using P %i and %i runs." % (P,runs))
|
2006-11-21 13:40:50 +00:00
|
|
|
results = removeattacks (testlist, P, runs)
|
|
|
|
if len(results) < len(testlist):
|
|
|
|
attacked = []
|
|
|
|
for i in range(0,len(testlist)):
|
|
|
|
if testlist[i] not in results:
|
|
|
|
attacked.append(testlist[i])
|
2020-10-27 21:09:03 +00:00
|
|
|
print("Using P %i and %i runs, we find attacks on %s" % (P,runs, str(attacked)))
|
|
|
|
print("Therefore, we are left with %i candidates: " % (len(results)), results)
|
2006-11-21 13:40:50 +00:00
|
|
|
|
|
|
|
return results
|
|
|
|
|
|
|
|
def main():
|
|
|
|
candidates = startset()
|
|
|
|
for P in range(3,7):
|
|
|
|
for rundiff in range(0,5):
|
|
|
|
candidates = scan(candidates,P,P+rundiff)
|
|
|
|
|
2020-10-27 21:09:03 +00:00
|
|
|
print()
|
|
|
|
print("Good variants:")
|
|
|
|
print(candidates)
|
2006-11-21 13:40:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
main()
|