Changeset - 0c78bfbee218
[Not reviewed]
default
0 2 1
Laman - 3 years ago 2022-03-03 22:36:36

compatibility with python<3.9
3 files changed with 11 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/shamira/fft.py
Show inline comments
 
# GNU GPLv3, see LICENSE
 

	
 
import math
 
import cmath
 
import itertools
 
from functools import cache
 

	
 
from .util import cache
 
from .gf256 import gfmul, gfpow
 

	
 
# divisors of 255 and their factors in natural numbers
 
DIVISORS = [3, 5, 15, 17, 51, 85, 255]
 
FACTORS = {3: [3], 5: [5], 15: [3, 5], 17: [17], 51: [3, 17], 85: [5, 17], 255: [3, 5, 17]}
 
# values of n-th square roots in GF256
src/shamira/gf256.py
Show inline comments
 
# GNU GPLv3, see LICENSE
 

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

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

	
 
from .util import cache
 

	
 

	
 
def _gfmul(a, b):
 
	"""Basic multiplication. Russian peasant algorithm."""
 
	res = 0
 
	while a and b:
 
		if b&1: res ^= a
src/shamira/util.py
Show inline comments
 
new file 100644
 
try:
 
	from functools import cache
 
except ImportError:  # Python<3.9
 
	from functools import lru_cache
 

	
 
	def cache(f):
 
		return lru_cache(maxsize=None)(f)
0 comments (0 inline, 0 general)