diff options
| author | J08nY | 2024-07-15 14:51:27 +0200 |
|---|---|---|
| committer | J08nY | 2024-07-15 14:59:12 +0200 |
| commit | 72c5f70c01af2c16f76dc6ddba7de55cc6d9583f (patch) | |
| tree | 55ce512b6e94d643fab3bb8bb5af6738ff048b91 /pyecsca | |
| parent | 1f8e220d8e28f7126ddb72daf127077809a5ea43 (diff) | |
| download | pyecsca-72c5f70c01af2c16f76dc6ddba7de55cc6d9583f.tar.gz pyecsca-72c5f70c01af2c16f76dc6ddba7de55cc6d9583f.tar.zst pyecsca-72c5f70c01af2c16f76dc6ddba7de55cc6d9583f.zip | |
Improve mod docs.
Diffstat (limited to 'pyecsca')
| -rw-r--r-- | pyecsca/ec/mod.py | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/pyecsca/ec/mod.py b/pyecsca/ec/mod.py index 4221a93..7637fd4 100644 --- a/pyecsca/ec/mod.py +++ b/pyecsca/ec/mod.py @@ -5,7 +5,8 @@ The base class :py:class:`Mod` dynamically dispatches to the implementation chosen by the runtime configuration of the library (see :py:class:`pyecsca.misc.cfg.Config`). A Python integer based implementation is available under :py:class:`RawMod`. A symbolic implementation based on sympy is available under :py:class:`SymbolicMod`. If -`gmpy2` is installed, a GMP based implementation is available under :py:class:`GMPMod`. +`gmpy2` is installed, a GMP based implementation is available under :py:class:`GMPMod`. If `python-flint` is +installed, a flint based implementation is available under :py:class:`FlintMod`. """ import random import secrets @@ -162,7 +163,40 @@ _mod_order = ["gmp", "flint", "python"] @public class Mod: - """An element x of ℤₙ.""" + """ + An element x of ℤₙ. + + .. note:: + This class dispatches to one of :py:class:`RawMod`, :py:class:`GMPMod` or :py:class:`FlintMod` + based on what packages are installed and what implementation is configured (see + :py:module:`pyecsca.misc.cfg`). + + Has all the usual special methods that upcast integers automatically: + + >>> a = Mod(3, 5) + >>> b = Mod(2, 5) + >>> a + b + 0 + >>> a * 2 + 1 + >>> a == 3 + True + >>> a == -2 + True + >>> -a + 2 + + Plus some additional useful things: + + >>> a.inverse() + 2 + >>> a.is_residue() + False + >>> (a**2).is_residue() + True + >>> (a**2).sqrt() == a + True + """ x: Any n: Any @@ -204,6 +238,11 @@ class Mod: return self.__class__(self.n - self.x, self.n) def bit_length(self): + """ + Compute the bit length of this element (in its positive integer representation). + + :return: The bit-length. + """ raise NotImplementedError def inverse(self) -> "Mod": |
