From the abstract of [E21b]: "We show that given the order of a single element selected uniformly at random from
This repository contains a Sage script factor.sage
that implements the factoring algorithm in [E21b].
For test purposes, it furthermore contains a script factor-test.sage
that simulates order finding.
Note that the aforementioned scripts were developed for academic research purposes. They grew out of our research project in an organic manner as research questions were posed and answered. They are distributed "as is" without warranty of any kind, either expressed or implied. For further details, see the license.
It is possible to further optimize portions of the scripts and the procedures therein. However, the current scripts perform sufficiently well for our purposes, in that they clearly show that it is virtually always possible to completely factor any integer
To install Sage under Ubuntu 20.04 LTS, simply execute:
$ sudo apt install sagemath
For other Linux and Unix distributions, or operating systems, you may need to download Sage and install it manually. These scripts were developed for Sage 9.3.
Launch Sage and attach the scripts factor.sage
and factor-test.sage
, by executing:
$ sage
(..)
sage: %attach factor.sage
sage: %attach factor-test.sage
To completely factor
sage: factor_completely(r, N, c = 1)
Above
As is explained in [E21b], by increasing
To better understand why, recall from [E21b] that if some moderate product of small prime factors is missing from the order
Note furthermore that by default the function will continue to iterate until the complete factorization is found, or until Ctrl-C is pressed. The constant
The factor-test.sage
script implements two types of order-finding simulators:
-
Given the factorization of
$N$ , and an element$g \in \mathbb Z_N^*$ , the first type of order-finding simulator yields either the order$r$ of$g$ , or a heuristic approximation of$r$ that is correct with very high probability.To be more specific: If the factorization of
$p_i - 1$ is known for all$i \in [1, n]$ , where$N = {\prod}_{i = 1}^n p_i^{e_i}$ , order finding can be performed exactly. Otherwise, a heuristic approximation can be computed by performing trial division to identify all small factors of$p_i - 1$ for$i \in [1, n]$ . For further details, see Appendix A of [E21b]. -
Given the factorization of
$N$ , the second type of order-finding simulator yields the order$r$ of an element$g$ selected uniformly at random from$\mathbb Z_N^*$ . This without explicitly computing$g$ .This approach to simulating order finding is not described in [E21b]. For further details, see instead the documentation of the
test_of_random_pi_ei()
function in thefactor-test.sage
script.
To test the factoring algorithm by performing exact order finding for a random integer
sage: test_of_random_N(m = 192, c = 1)
This function will first select
Finally, it will call factor_completely()
with
To test the factoring algorithm by performing order finding given the factorization of
sage: test_of_random_pi_ei(l = 1024, n = 2, e_max = 1, c = 1, exact = True)
This function will first select
-
If
exact
is set toFalse
, this function will first select$g$ uniformly at random from$\mathbb Z_N^*$ . It will then heuristically determine the order$r$ of$g$ using the first type of simulator described above. -
If
exact
is set toTrue
, as is the default, this function will exactly compute the order$r$ of an element$g$ selected uniformly at random from$\mathbb Z_N^*$ , using the second type of simulator described above.This without explicitly computing
$g$ . (Note that$g$ is not used by the factoring algorithm in [E21b].)
Finally, this function will call factor_completely()
with
To run the test suite described in Appendix A.3 of [E21b], execute:
sage: test_all_appendix_A(exact = True)
This function in turn calls the test_of_random_pi_ei()
function documented above.
-
Set the
exact
flag toFalse
to perform heuristic order finding as described in Appendix A of [E21b]. -
Set the
exact
flag toTrue
, as is the default, to instead perform exact order finding at the expense of foregoing the computation of$g$ . This is an improvement of the procedure in Appendix A of [E21b].
For further details on the exact
flag, see the documentation for the test_of_random_pi_ei()
function.
This implementation supports several optimizations that may be enabled or disabled by passing along flags to the functions described in the above sections. For more information, see the notes on optimizations.
These scripts were developed by Martin Ekerå, in part at KTH, the Royal Institute of Technology, in Stockholm, Sweden. Valuable comments and advice were provided by Johan Håstad throughout the development process.
Funding and support was provided by the Swedish NCSA that is a part of the Swedish Armed Forces.