From ced855257315fdf615816b0fd292c9c96c997119 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 7 Jan 2025 13:47:51 -0800 Subject: [PATCH 1/5] Replace sage.all imports --- cry/eq/interpolator.py | 11 +++++-- cry/sagestuff.py | 68 +++++++++++++++++------------------------- tests_sage/test_rsa.py | 10 ++++--- 3 files changed, 43 insertions(+), 46 deletions(-) diff --git a/cry/eq/interpolator.py b/cry/eq/interpolator.py index 4f8ca66..09fdddc 100644 --- a/cry/eq/interpolator.py +++ b/cry/eq/interpolator.py @@ -1,7 +1,14 @@ -from sage.all import * - from itertools import product +try: + import sage.all_cmdline +except ImportError: + import sage.all__sagemath_modules + +from sage.rings.ideal import Ideal +from sage.misc.misc_c import prod +from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing + # class Interpolator: # """ diff --git a/cry/sagestuff.py b/cry/sagestuff.py index 88a8a8f..bc2038c 100644 --- a/cry/sagestuff.py +++ b/cry/sagestuff.py @@ -1,51 +1,39 @@ """ Trying to import only required stuff from sage. Single point of import is good. - -Tried to import from inner modules, but probably worthless. -Seems sage.all must be imported. """ # sage is a gigantic mess -from sage.all_cmdline import ( - copy, power_mod, - Integer, Zmod, ZZ, QQ, RR, CDF, Integer, GF, - loads, dumps, - matrix, identity_matrix, random_matrix, matrix_plot, - vector, random_vector, - binomial, - lcm, gcd, log, - Combinations, Permutation, - LinearCode, - floor, ceil, inverse_mod, floor, -) - -from random import randint, shuffle, choice - -# import sage.structure - -# from sage.plot.matrix_plot import matrix_plot - -# from sage.misc.persist import loads, dumps - -# from sage.matrix.constructor import matrix, identity_matrix, random_matrix -# from sage.modules.free_module_element import vector -# Matrix = matrix -# from sage.rings.finite_rings.finite_field_constructor import GF -# from sage.rings.integer import Integer -# from sage.rings.integer_ring import ZZ -from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing -from sage.rings.polynomial.polynomial_ring_constructor import BooleanPolynomialRing_constructor as BooleanPolynomialRing -# from sage.groups.matrix_gps.catalog import GL +try: + import sage.all_cmdline +except ImportError: + import sage.all__sagemath_modules -# from sage.functions import log - -# from sage.misc.prandom import randint, shuffle, choice -# from sage.arith.all import lcm, gcd +from copy import copy +from random import randint, shuffle, choice +from sage.arith.functions import lcm +from sage.arith.misc import GCD as gcd, inverse_mod, power_mod +from sage.coding.linear_code import LinearCode +from sage.combinat.combination import Combinations +from sage.combinat.permutation import Permutation from sage.crypto.boolean_function import BooleanFunction - -# from sage.combinat.combination import Combinations -# from sage.functions.other import binomial +from sage.functions.other import binomial, ceil, floor +from sage.matrix.constructor import Matrix as matrix +from sage.matrix.special import identity_matrix, random_matrix +from sage.misc.functional import log +from sage.misc.persist import dumps, loads +from sage.modules.free_module_element import free_module_element as vector +from sage.modules.free_module_element import random_vector +from sage.plot.matrix_plot import matrix_plot +from sage.rings.complex_double import CDF +from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF +from sage.rings.finite_rings.integer_mod_ring import IntegerModRing as Zmod +from sage.rings.integer import Integer +from sage.rings.integer_ring import ZZ +from sage.rings.polynomial.polynomial_ring_constructor import BooleanPolynomialRing_constructor as BooleanPolynomialRing +from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing +from sage.rings.rational_field import QQ +from sage.rings.real_mpfr import RR diff --git a/tests_sage/test_rsa.py b/tests_sage/test_rsa.py index 6b55656..56008f9 100644 --- a/tests_sage/test_rsa.py +++ b/tests_sage/test_rsa.py @@ -1,7 +1,9 @@ -from sage.all import ( - EllipticCurve, Zmod, QQ, - is_prime, inverse_mod, crt -) +from sage.schemes.elliptic_curves.constructor import EllipticCurve +from sage.rings.finite_rings.integer_mod_ring import IntegerModRing as Zmod +from sage.rings.rational_field import Q as QQ +from sage.arith.misc import is_prime +from sage.arith.misc import inverse_mod +from sage.arith.misc import CRT as crt from bint import Bin from cry.env import RSA From 5410fe7542eca477784165168ec38d0e94cd1ead Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 7 Jan 2025 13:48:16 -0800 Subject: [PATCH 2/5] Update 'from bint' imports to 'from binteger' --- tests_sage/test_lattice.py | 2 +- tests_sage/test_rsa.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests_sage/test_lattice.py b/tests_sage/test_lattice.py index 2a62cb4..df137ab 100644 --- a/tests_sage/test_lattice.py +++ b/tests_sage/test_lattice.py @@ -3,7 +3,7 @@ def test_SECCON_2020_sharsable(): - from bint import Bin + from binteger import Bin # SECCON 2020 - sharsable n = 142793817321992828777925840162504083304079023834001118099549928854335392622287928254035247188624975743042449746066633491912316354241339908190889792327014012472372654378644158878787350693992259970146885854641856991605625756536504266728483088687985429310233421251081614258665472164668993082471923690196082829593 # noqa diff --git a/tests_sage/test_rsa.py b/tests_sage/test_rsa.py index 56008f9..a7282e0 100644 --- a/tests_sage/test_rsa.py +++ b/tests_sage/test_rsa.py @@ -5,7 +5,7 @@ from sage.arith.misc import inverse_mod from sage.arith.misc import CRT as crt -from bint import Bin +from binteger import Bin from cry.env import RSA From 034214c3887fb6802df3c964bd9a330ab61474b8 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 13 Sep 2025 22:23:14 -0700 Subject: [PATCH 3/5] pyproject.toml: Add extra 'passagemath' --- pyproject.toml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 9e8777c..20e0576 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,27 @@ dependencies = [ [project.urls] repository = "http://github.com/hellman/cry" +[tool.poetry.dependencies] +python = "^3.5" +binteger = "^0.8.0" + +passagemath-brial = { version = "^10.6", optional = true } +passagemath-modules = { version = "^10.6", optional = true } +passagemath-plot = { version = "^10.6", optional = true } +passagemath-repl = { version = "^10.6", optional = true } +passagemath-schemes = { version = "^10.6", optional = true } +passagemath-symbolics = { version = "^10.6", optional = true } + +[tool.poetry.extras] +passagemath = [ + "passagemath-brial", + "passagemath-modules", + "passagemath-plot", + "passagemath-repl", + "passagemath-schemes", + "passagemath-symbolics", +] + [tool.poetry.group.dev.dependencies] pytest = "^6.1.1" From a3730a60c4267d811734cc846892fa73be3020aa Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 7 Jan 2025 13:48:54 -0800 Subject: [PATCH 4/5] tox.ini: New --- tox.ini | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tox.ini diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..ea24396 --- /dev/null +++ b/tox.ini @@ -0,0 +1,15 @@ +# tox -c tox-passagemath.ini +[tox] +envlist = passagemath + +[testenv:passagemath] +usedevelop = True +extras = passagemath +deps = pytest + +setenv = + # For access to _doctest_environment.py + PYTHONPATH=. + +commands = + pytest tests_sage/ From e17cf591581ba1a0ce373d8950f6a978ff396a31 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 13 Sep 2025 22:29:47 -0700 Subject: [PATCH 5/5] pyproject.toml: Switch to 'project.optional-dependencies' table for passagemath --- pyproject.toml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 20e0576..8cd4246 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,18 +23,7 @@ dependencies = [ [project.urls] repository = "http://github.com/hellman/cry" -[tool.poetry.dependencies] -python = "^3.5" -binteger = "^0.8.0" - -passagemath-brial = { version = "^10.6", optional = true } -passagemath-modules = { version = "^10.6", optional = true } -passagemath-plot = { version = "^10.6", optional = true } -passagemath-repl = { version = "^10.6", optional = true } -passagemath-schemes = { version = "^10.6", optional = true } -passagemath-symbolics = { version = "^10.6", optional = true } - -[tool.poetry.extras] +[project.optional-dependencies] passagemath = [ "passagemath-brial", "passagemath-modules",