Changeset - f2079f566ab5
[Not reviewed]
default
0 3 0
Laman - 4 years ago 2020-12-07 22:36:03

optimized computation by caching the results
3 files changed with 6 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/shamira/benchmark.py
Show inline comments
 
@@ -21,7 +21,7 @@ def measure(args):
 
def profile(args):
 
	t = TestShamira()
 

	
 
	cProfile.runctx(r"""t.test_generate_reconstruct()""", globals=globals(), locals=locals())
 
	cProfile.runctx(r"""t.test_generate_reconstruct()""", globals=globals(), locals=locals(), sort="cumtime")
 

	
 

	
 
def build_subparsers(parent):
src/shamira/fft.py
Show inline comments
 
import math
 
import cmath
 
import itertools
 
from functools import cache
 

	
 
from .gf256 import gfmul, gfpow
 

	
 
@@ -20,6 +21,7 @@ def ceil_size(n):
 
	return ni
 

	
 

	
 
@cache
 
def precompute_x(n):
 
	"""Return a geometric sequence [1, w, w**2, ..., w**(n-1)], where w**n==1.
 
	This can be done only for certain values of n."""
src/shamira/gf256.py
Show inline comments
 
@@ -2,7 +2,7 @@
 

	
 
"""Arithmetic operations on Galois Field 2**8. See https://en.wikipedia.org/wiki/Finite_field_arithmetic"""
 

	
 
from functools import reduce
 
from functools import reduce, cache
 
import operator
 

	
 

	
 
@@ -29,6 +29,7 @@ L[1] = 0
 
INV = [E[255-L[i]] if i!=0 else None for i in range(256)]  # multiplicative inverse
 

	
 

	
 
@cache
 
def gfmul(a, b):
 
	"""Fast multiplication. Basic multiplication is expensive. a*b==g**(log(a)+log(b))"""
 
	assert 0<=a<=255, 0<=b<=255
 
@@ -38,6 +39,7 @@ def gfmul(a, b):
 
	return E[t]
 

	
 

	
 
@cache
 
def gfpow(x, k):
 
	"""Compute x**k."""
 
	i = 1
0 comments (0 inline, 0 general)