aboutsummaryrefslogtreecommitdiffstats
path: root/src/scripts/comba.py
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-04-08 18:43:18 -0400
committerJack Lloyd <[email protected]>2018-04-08 18:43:18 -0400
commitc921a1bff2f267dd94f7e4aa8f30341e83d8d52f (patch)
treeea87e3931721268df068ba921f8c78bd4d610145 /src/scripts/comba.py
parent8b4f53112c4987504b341d960b9c7df07f9d5b8b (diff)
Convert comba script to Python3
Diffstat (limited to 'src/scripts/comba.py')
-rwxr-xr-xsrc/scripts/comba.py52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/scripts/comba.py b/src/scripts/comba.py
index 2fa95fb24..8cff76f8f 100755
--- a/src/scripts/comba.py
+++ b/src/scripts/comba.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2
+#!/usr/bin/python3
import sys
import datetime
@@ -12,10 +12,10 @@ def comba_indexes(N):
indexes = []
- for i in xrange(0, 2*N):
+ for i in range(0, 2*N):
x = []
- for j in xrange(max(0, i-N+1), min(N, i+1)):
+ for j in range(max(0, i-N+1), min(N, i+1)):
x += [(j,i-j)]
indexes += [sorted(x)]
@@ -25,10 +25,10 @@ def comba_sqr_indexes(N):
indexes = []
- for i in xrange(0, 2*N):
+ for i in range(0, 2*N):
x = []
- for j in xrange(max(0, i-N+1), min(N, i+1)):
+ for j in range(max(0, i-N+1), min(N, i+1)):
if j < i-j:
x += [(j,i-j)]
else:
@@ -46,14 +46,14 @@ def comba_multiply_code(N):
for (i,idx) in zip(range(0, len(indexes)), indexes):
for pair in idx:
- print " word3_muladd(&%s, &%s, &%s, x[%2d], y[%2d]);" % (w2, w1, w0, pair[0], pair[1])
+ print(" word3_muladd(&%s, &%s, &%s, x[%2d], y[%2d]);" % (w2, w1, w0, pair[0], pair[1]))
if i < 2*N-2:
- print " z[%2d] = %s; %s = 0;\n" % (i, w0, w0)
+ print(" z[%2d] = %s; %s = 0;\n" % (i, w0, w0))
else:
- print " z[%2d] = %s;" % (i, w0)
+ print(" z[%2d] = %s;" % (i, w0))
(w0,w1,w2) = (w1,w2,w0)
- #print "z[%2d] = w0; w0 = w1; w1 = w2; w2 = 0;" % (i)
+ #print("z[%2d] = w0; w0 = w1; w1 = w2; w2 = 0;" % (i))
def comba_square_code(N):
indexes = comba_sqr_indexes(N)
@@ -65,14 +65,14 @@ def comba_square_code(N):
for (rnd,idx) in zip(range(0, len(indexes)), indexes):
for (i,pair) in zip(range(0, len(idx)), idx):
if pair[0] == pair[1]:
- print " word3_muladd (&%s, &%s, &%s, x[%2d], x[%2d]);" % (w2, w1, w0, pair[0], pair[1])
+ print(" word3_muladd (&%s, &%s, &%s, x[%2d], x[%2d]);" % (w2, w1, w0, pair[0], pair[1]))
elif i % 2 == 0:
- print " word3_muladd_2(&%s, &%s, &%s, x[%2d], x[%2d]);" % (w2, w1, w0, pair[0], pair[1])
+ print(" word3_muladd_2(&%s, &%s, &%s, x[%2d], x[%2d]);" % (w2, w1, w0, pair[0], pair[1]))
if rnd < 2*N-2:
- print " z[%2d] = %s; %s = 0;\n" % (rnd, w0, w0)
+ print(" z[%2d] = %s; %s = 0;\n" % (rnd, w0, w0))
else:
- print " z[%2d] = %s;" % (rnd, w0)
+ print(" z[%2d] = %s;" % (rnd, w0))
(w0,w1,w2) = (w1,w2,w0)
@@ -80,7 +80,7 @@ def main(args = None):
if args is None:
args = sys.argv
- print """/*
+ print("""/*
* Comba Multiplication and Squaring
*
* This file was automatically generated by %s on %s
@@ -92,28 +92,28 @@ def main(args = None):
#include <botan/internal/mp_asmi.h>
namespace Botan {
-""" % (sys.argv[0], datetime.date.today().strftime("%Y-%m-%d"))
+""" % (sys.argv[0], datetime.date.today().strftime("%Y-%m-%d")))
for n in [4,6,8,9,16]:
- print "/*\n* Comba %dx%d Squaring\n*/" % (n, n)
- print "void bigint_comba_sqr%d(word z[%d], const word x[%d])" % (n, 2*n, n)
- print " {"
- print " word w2 = 0, w1 = 0, w0 = 0;\n"
+ print("/*\n* Comba %dx%d Squaring\n*/" % (n, n))
+ print("void bigint_comba_sqr%d(word z[%d], const word x[%d])" % (n, 2*n, n))
+ print(" {")
+ print(" word w2 = 0, w1 = 0, w0 = 0;\n")
comba_square_code(n)
- print " }\n"
+ print(" }\n")
- print "/*\n* Comba %dx%d Multiplication\n*/" % (n, n)
- print "void bigint_comba_mul%d(word z[%d], const word x[%d], const word y[%d])" % (n, 2*n, n, n)
- print " {"
- print " word w2 = 0, w1 = 0, w0 = 0;\n"
+ print("/*\n* Comba %dx%d Multiplication\n*/" % (n, n))
+ print("void bigint_comba_mul%d(word z[%d], const word x[%d], const word y[%d])" % (n, 2*n, n, n))
+ print(" {")
+ print(" word w2 = 0, w1 = 0, w0 = 0;\n")
comba_multiply_code(n)
- print " }\n"
+ print(" }\n")
- print "}"
+ print("}")
if __name__ == '__main__':
sys.exit(main())