diff options
| author | J08nY | 2024-07-11 15:45:54 +0200 |
|---|---|---|
| committer | J08nY | 2024-07-11 15:45:54 +0200 |
| commit | 43e105655bd2de6b64ddb3c4ddf4b965bc196e6b (patch) | |
| tree | 0cdb44eba00cad7d2e87a41e6c202f33578ae92a /pyecsca/ec/mod.py | |
| parent | b85ebefb35e2661e87a8c1be16a222bb6eae6a1f (diff) | |
| download | pyecsca-43e105655bd2de6b64ddb3c4ddf4b965bc196e6b.tar.gz pyecsca-43e105655bd2de6b64ddb3c4ddf4b965bc196e6b.tar.zst pyecsca-43e105655bd2de6b64ddb3c4ddf4b965bc196e6b.zip | |
Diffstat (limited to 'pyecsca/ec/mod.py')
| -rw-r--r-- | pyecsca/ec/mod.py | 41 |
1 files changed, 10 insertions, 31 deletions
diff --git a/pyecsca/ec/mod.py b/pyecsca/ec/mod.py index 07b2734..2aa4bdd 100644 --- a/pyecsca/ec/mod.py +++ b/pyecsca/ec/mod.py @@ -457,27 +457,6 @@ class Undefined(Mod): return NotImplemented -@lru_cache -def __ff_cache(n): - return FF(n) - - -def _symbolic_check(func): - @wraps(func) - def method(self, other): - if type(self) is not type(other): - if type(other) is int: - other = self.__class__(__ff_cache(self.n)(other), self.n) - else: - other = self.__class__(other, self.n) - else: - if self.n != other.n: - raise ValueError - return func(self, other) - - return method - - @public class SymbolicMod(Mod): """A symbolic element x of ℤₙ (implemented using sympy).""" @@ -493,19 +472,19 @@ class SymbolicMod(Mod): self.x = x self.n = n - @_symbolic_check + @_check def __add__(self, other) -> "SymbolicMod": return self.__class__((self.x + other.x), self.n) - @_symbolic_check + @_check def __radd__(self, other) -> "SymbolicMod": return self + other - @_symbolic_check + @_check def __sub__(self, other) -> "SymbolicMod": return self.__class__((self.x - other.x), self.n) - @_symbolic_check + @_check def __rsub__(self, other) -> "SymbolicMod": return -self + other @@ -527,27 +506,27 @@ class SymbolicMod(Mod): def __invert__(self) -> "SymbolicMod": return self.inverse() - @_symbolic_check + @_check def __mul__(self, other) -> "SymbolicMod": return self.__class__(self.x * other.x, self.n) - @_symbolic_check + @_check def __rmul__(self, other) -> "SymbolicMod": return self * other - @_symbolic_check + @_check def __truediv__(self, other) -> "SymbolicMod": return self * ~other - @_symbolic_check + @_check def __rtruediv__(self, other) -> "SymbolicMod": return ~self * other - @_symbolic_check + @_check def __floordiv__(self, other) -> "SymbolicMod": return self * ~other - @_symbolic_check + @_check def __rfloordiv__(self, other) -> "SymbolicMod": return ~self * other |
