FindAFactor 3.7.0__cp313-cp313-macosx_15_0_arm64.whl → 3.8.1__cp313-cp313-macosx_15_0_arm64.whl
Sign up to get free protection for your applications and to get access to all the features.
- FindAFactor/find_a_factor.py +1 -1
- FindAFactor-3.8.1.dist-info/METADATA +27 -0
- FindAFactor-3.8.1.dist-info/RECORD +8 -0
- _find_a_factor.cpython-313-darwin.so +0 -0
- FindAFactor-3.7.0.dist-info/METADATA +0 -116
- FindAFactor-3.7.0.dist-info/RECORD +0 -8
- {FindAFactor-3.7.0.dist-info → FindAFactor-3.8.1.dist-info}/LICENSE +0 -0
- {FindAFactor-3.7.0.dist-info → FindAFactor-3.8.1.dist-info}/WHEEL +0 -0
- {FindAFactor-3.7.0.dist-info → FindAFactor-3.8.1.dist-info}/top_level.txt +0 -0
FindAFactor/find_a_factor.py
CHANGED
@@ -7,7 +7,7 @@ def find_a_factor(n,
|
|
7
7
|
node_count=int(os.environ.get('FINDAFACTOR_NODE_COUNT')) if os.environ.get('FINDAFACTOR_NODE_COUNT') else 1,
|
8
8
|
node_id=int(os.environ.get('FINDAFACTOR_NODE_ID')) if os.environ.get('FINDAFACTOR_NODE_ID') else 0,
|
9
9
|
trial_division_level=int(os.environ.get('FINDAFACTOR_TRIAL_DIVISION_LEVEL')) if os.environ.get('FINDAFACTOR_TRIAL_DIVISION_LEVEL') else (1<<20),
|
10
|
-
gear_factorization_level=int(os.environ.get('FINDAFACTOR_GEAR_FACTORIZATION_LEVEL')) if os.environ.get('FINDAFACTOR_GEAR_FACTORIZATION_LEVEL') else
|
10
|
+
gear_factorization_level=int(os.environ.get('FINDAFACTOR_GEAR_FACTORIZATION_LEVEL')) if os.environ.get('FINDAFACTOR_GEAR_FACTORIZATION_LEVEL') else 11,
|
11
11
|
wheel_factorization_level=int(os.environ.get('FINDAFACTOR_WHEEL_FACTORIZATION_LEVEL')) if os.environ.get('FINDAFACTOR_WHEEL_FACTORIZATION_LEVEL') else 7,
|
12
12
|
smoothness_bound_multiplier=float(os.environ.get('FINDAFACTOR_SMOOTHNESS_BOUND_MULTIPLIER')) if os.environ.get('FINDAFACTOR_SMOOTHNESS_BOUND_MULTIPLIER') else 1.0,
|
13
13
|
batch_size_multiplier=float(os.environ.get('FINDAFACTOR_BATCH_SIZE_MULTIPLIER')) if os.environ.get('FINDAFACTOR_BATCH_SIZE_MULTIPLIER') else 2048.0):
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Metadata-Version: 2.2
|
2
|
+
Name: FindAFactor
|
3
|
+
Version: 3.8.1
|
4
|
+
Summary: Find any nontrivial factor of a number
|
5
|
+
Home-page: https://github.com/vm6502q/FindAFactor
|
6
|
+
Author: Dan Strano
|
7
|
+
Author-email: Dan Strano <stranoj@gmail.com>
|
8
|
+
Maintainer-email: Dan Strano <stranoj@gmail.com>
|
9
|
+
License: MIT License
|
10
|
+
Project-URL: Homepage, https://github.com/vm6502q/FindAFactor
|
11
|
+
Project-URL: Documentation, https://github.com/vm6502q/FindAFactor/blob/main/README.md
|
12
|
+
Project-URL: Repository, https://github.com/vm6502q/FindAFactor
|
13
|
+
Project-URL: Issues, https://github.com/vm6502q/FindAFactor/issues
|
14
|
+
Classifier: Environment :: Console
|
15
|
+
Classifier: Intended Audience :: Developers
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
18
|
+
Classifier: Programming Language :: C++
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
22
|
+
Classifier: Topic :: Scientific/Engineering
|
23
|
+
Requires-Python: >=3.8
|
24
|
+
Description-Content-Type: text/markdown
|
25
|
+
License-File: LICENSE
|
26
|
+
Dynamic: author
|
27
|
+
Dynamic: home-page
|
@@ -0,0 +1,8 @@
|
|
1
|
+
_find_a_factor.cpython-313-darwin.so,sha256=XhJGyhAJMlBXLsENVnpjqB0TeGJTQnAq8ubvK6WBRZg,275016
|
2
|
+
FindAFactor/__init__.py,sha256=z12lYiLTSXmc8FpKk4tqkSADlHxEV-NqWyA1d5OuQAQ,40
|
3
|
+
FindAFactor/find_a_factor.py,sha256=5P_1BcoLIFr8JHeLe4smpect7G7TnEDuf4ZPNAqcD3Y,2027
|
4
|
+
FindAFactor-3.8.1.dist-info/LICENSE,sha256=kM5ErD_w66mShD_pmEXez6Evb2_MTLRHykc0qdUWEFY,1085
|
5
|
+
FindAFactor-3.8.1.dist-info/METADATA,sha256=IdQSZqjtaSwUa0zcWrV8BCo_cMhj_RQSMWrlGvrflvs,1102
|
6
|
+
FindAFactor-3.8.1.dist-info/WHEEL,sha256=8MDYB8qOpICHXsmvikvrTDt0NBN7mgF9tE1rvEyJ6WE,109
|
7
|
+
FindAFactor-3.8.1.dist-info/top_level.txt,sha256=WoOrEcqIwo8A96WXAtimPshsFZfT5d00SvMC6rVKAn0,27
|
8
|
+
FindAFactor-3.8.1.dist-info/RECORD,,
|
Binary file
|
@@ -1,116 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.2
|
2
|
-
Name: FindAFactor
|
3
|
-
Version: 3.7.0
|
4
|
-
Summary: Find any nontrivial factor of a number
|
5
|
-
Home-page: https://github.com/vm6502q/FindAFactor
|
6
|
-
Author: Dan Strano
|
7
|
-
Author-email: dan@unitary.fund
|
8
|
-
License: MIT
|
9
|
-
Classifier: Environment :: Console
|
10
|
-
Classifier: Intended Audience :: Developers
|
11
|
-
Classifier: Intended Audience :: Science/Research
|
12
|
-
Classifier: Operating System :: POSIX :: Linux
|
13
|
-
Classifier: Programming Language :: C++
|
14
|
-
Classifier: Programming Language :: Python :: 3.8
|
15
|
-
Classifier: Programming Language :: Python :: 3.9
|
16
|
-
Classifier: Programming Language :: Python :: 3.10
|
17
|
-
Classifier: Topic :: Scientific/Engineering
|
18
|
-
Description-Content-Type: text/markdown
|
19
|
-
License-File: LICENSE
|
20
|
-
Requires-Dist: pybind11
|
21
|
-
Dynamic: author
|
22
|
-
Dynamic: author-email
|
23
|
-
Dynamic: classifier
|
24
|
-
Dynamic: description
|
25
|
-
Dynamic: description-content-type
|
26
|
-
Dynamic: home-page
|
27
|
-
Dynamic: license
|
28
|
-
Dynamic: requires-dist
|
29
|
-
Dynamic: summary
|
30
|
-
|
31
|
-
# FindAFactor
|
32
|
-
Find any nontrivial factor of a number
|
33
|
-
|
34
|
-
## Copyright and license
|
35
|
-
(c) Daniel Strano and the Qrack contributors 2017-2025. All rights reserved.
|
36
|
-
|
37
|
-
## Installation
|
38
|
-
From PyPi:
|
39
|
-
```
|
40
|
-
pip3 install FindAFactor
|
41
|
-
```
|
42
|
-
|
43
|
-
From Source: install `pybind11`, then
|
44
|
-
```
|
45
|
-
pip3 install .
|
46
|
-
```
|
47
|
-
in the root source directory (with `setup.py`).
|
48
|
-
|
49
|
-
Windows users might find Windows Subsystem Linux (WSL) to be the easier and preferred choice for installation.
|
50
|
-
|
51
|
-
## Usage
|
52
|
-
|
53
|
-
```py
|
54
|
-
from FindAFactor import find_a_factor
|
55
|
-
|
56
|
-
to_factor = 1000
|
57
|
-
|
58
|
-
factor = find_a_factor(
|
59
|
-
to_factor,
|
60
|
-
use_congruence_of_squares=False,
|
61
|
-
use_gaussian_elimination=False,
|
62
|
-
node_count=1, node_id=0,
|
63
|
-
trial_division_level=2**20,
|
64
|
-
gear_factorization_level=13,
|
65
|
-
wheel_factorization_level=7,
|
66
|
-
smoothness_bound_multiplier=1.0,
|
67
|
-
batch_size_multiplier=2048.0
|
68
|
-
)
|
69
|
-
```
|
70
|
-
|
71
|
-
The `find_a_factor()` function should return any nontrivial factor of `to_factor` (that is, any factor besides `1` or `to_factor`) if it exists. If a nontrivial factor does _not_ exist (i.e., the number to factor is prime), the function will return `1` or the original `to_factor`.
|
72
|
-
|
73
|
-
- `use_congruence_of_squares` (default value: `False`): This attempts to check congruence of squares with "smooth" numbers, if `true`.
|
74
|
-
- `use_gaussian_elimination` (default value: `False`): This option is only relevant if `use_congruence_of_squares=True`. In that case, if `use_gaussian_elimination` is `True`, then proper Gaussian elimination is used, with **O(N^3)** worst case complexity but using potentially much smaller "N" count of rows. If the option is `False`, rather than Gaussian elimination, the algorithm checks only for exact factorization parity duplicates in the "smooth" number rows, for **O(N^2)** worst case complexity, but using a potentially much larger "N" count of rows.
|
75
|
-
- `node_count` (default value: `1`): `FindAFactor` can perform factorization in a _distributed_ manner, across nodes, without network communication! When `node_count` is set higher than `1`, the search space for factors is segmented equally per node. If the number to factor is semiprime, and brute-force search is used instead of congruence of squares, for example, all nodes except the one that happens to contain the (unknown) prime factor less than the square root of `to_factor` will ultimately return `1`, while one node will find and return this factor. For best performance, every node involved in factorization should have roughly the same CPU throughput capacity.
|
76
|
-
- `node_id` (default value: `0`): This is the identifier of this node, when performing distributed factorization with `node_count` higher than `1`. `node_id` values start at `0` and go as high as `(node_count - 1)`.
|
77
|
-
- `trial_division_level` (default value: `2**20`): Trial division is carried out as a preliminary round for all primes up this number. If you need more primes for your smoothness bound, increase this level.
|
78
|
-
- `gear_factorization_level` (default value: `13`): This is the value up to which "wheel (and gear) factorization" and trial division are used to check factors and optimize "brute force," in general. The default value of `13` includes all prime factors of `13` and below and works well in general, though significantly higher might be preferred in certain cases.
|
79
|
-
- `wheel_factorization_level` (default value: `7`): "Wheel" vs. "gear" factorization balances two types of factorization wheel ("wheel" vs. "gear" design) that often work best when the "wheel" is only a few prime number levels lower than gear factorization. Optimized implementation for wheels is only available up to `13`. The primes above "wheel" level, up to "gear" level, are the primes used specifically for "gear" factorization.
|
80
|
-
- `smoothness_bound_multiplier` (default value: `1.0`): starting with the first prime number after wheel factorization, the congruence of squares approach (with Quadratic Sieve) takes a default "smoothness bound" with as many distinct prime numbers as bits in the number to factor (for default argument of `1.0` multiplier). To increase or decrease this number, consider it multiplied by the value of `smoothness_bound_multiplier`.
|
81
|
-
- `batch_size_multiplier` (default value: `2048.0`): Each `1.0` increment of the multiplier is 2 cycles of gear and wheel factorization, alternating every other cycle between bottom of guessing range and top of guessing range, for every thread in use.
|
82
|
-
|
83
|
-
All variables defaults can also be controlled by environment variables:
|
84
|
-
- `FINDAFACTOR_USE_CONGRUENCE_OF_SQUARES` (any value makes `True`, while default is `False`)
|
85
|
-
- `FINDAFACTOR_NODE_COUNT`
|
86
|
-
- `FINDAFACTOR_NODE_ID`
|
87
|
-
- `FINDAFACTOR_TRIAL_DIVISION_LEVEL`
|
88
|
-
- `FINDAFACTOR_GEAR_FACTORIZATION_LEVEL`
|
89
|
-
- `FINDAFACTOR_WHEEL_FACTORIZATION_LEVEL`
|
90
|
-
- `FINDAFACTOR_SMOOTHNESS_BOUND_MULTIPLIER`
|
91
|
-
- `FINDAFACTOR_BATCH_SIZE_MULTIPLIER`
|
92
|
-
|
93
|
-
## Factoring parameter strategy
|
94
|
-
|
95
|
-
The developer anticipates this single-function set of parameters, as API, is the absolutely most complicated FindAFactor likely ever needs to get. The _only_ required argument is `to_factor`, and it _just works,_ for any number that should reasonably take about less than a second to a few minutes. However, if you're running larger numbers for longer than that, of course, it's worth investing 15 to 30 minutes to read the explanation above in the `README` of every argument and play with the settings, a little. But, with these options, you have _total control to tune_ the algorithm in any all ways necessary to adapt to system resource footprint.
|
96
|
-
|
97
|
-
Advantage for `use_congruence_of_squares` is beyond the hardware scale of the developer's experiments, in practicality, but it can be shown to work correctly (at disadvantage, at small factoring bit-width scales). The anticipated use case is to turn this option on when approaching the size of modern-day RSA semiprimes in use.
|
98
|
-
|
99
|
-
If this is your use case, you want to specifically consider `smoothness_bound_multiplier`, `batch_size_multiplier`, and potentially `thread_count` for managing memory. By default, as many primes are kept for "smooth" number sieving as bits in the number to factor. This is multiplied by `smooth_bound_multiplier` (and cast to a discrete number of primes in total). This multiplier tends to predominate memory, but `batch_size_multiplier` can also cause problems if set too high or low, as a high value might exhaust memory, while a low value increases potentially nonproductive Gaussian elimination checks, which might be more efficient if batched higher. Our expectation is that most systems will benefit from significant experimentation with and fine tuning of `batch_size_multiplier` to something other than default, potentially to the point of using about half of available memory.
|
100
|
-
|
101
|
-
`wheel_factorization_level` and `gear_factorization_level` are common to both `use_congruence_of_squares` (i.e., Gaussian elimination for perfect squares) and "brute force." `11` for gear and `5` for wheel limit works well for small numbers. You'll definitely want to consider (gear/wheel) `13`/`7` or `17`/`11` (or even other values, maybe system-dependent) as your numbers to factor approach cryptographic relevance.
|
102
|
-
|
103
|
-
As for `node_count` and `node_id`, believe it or not, factoring parallelism can truly be that simple: just run different node IDs in the set on different (roughly homogenous) isolated CPUs, without networking. The only caveat is that you must manually detect when any single node has found an answer (which is trivial to verify) and manually interrupt other nodes still working (or leave them to complete on their own).
|
104
|
-
|
105
|
-
## About
|
106
|
-
This library was originally called ["Qimcifa"](https://github.com/vm6502q/qimcifa) and demonstrated a (Shor's-like) "quantum-inspired" algorithm for integer factoring. It has since been developed into a general factoring algorithm and tool.
|
107
|
-
|
108
|
-
`FindAFactor` uses heavily wheel-factorized brute-force "exhaust" numbers as "smooth" inputs to Quadratic Sieve, widely regarded as the asymptotically second fastest algorithm class known for cryptographically relevant semiprime factoring. Actually, the primary difference between Quadratic Sieve (QS, regarded second-fastest) and General Number Field Sieve (GNFS, fastest) is based in how "smooth" numbers are generated as intermediate inputs to Gaussian elimination, and the "brute-force exhaust" of Qimcifa provides smooth numbers rather than canonical polynomial generators for QS or GNFS, so whether `FindAFactor` is theoretically fastest depends on how good its smooth number generation is (which is an open question). `FindAFactor` is C++ based, with `pybind11`, which tends to make it faster than pure Python approaches. For the quick-and-dirty application of finding _any single_ nontrivial factor, something like at least 80% of positive integers will factorize in a fraction of a second, but the most interesting cases to consider are semiprime numbers, for which `FindAFactor` should be about as asymptotically competitive as similar Quadratic Sieve implementations.
|
109
|
-
|
110
|
-
Our original contribution to Quadratic Sieve seems to be wheel factorization to 13 or 17 and maybe the idea of using the "exhaust" of a brute-force search for smooth number inputs for Quadratic Sieve. For wheel factorization (or "gear factorization"), we collect a short list of the first primes and remove all of their multiples from a "brute-force" guessing range by mapping a dense contiguous integer set, to a set without these multiples, relying on both a traditional "wheel," up to a middle prime number (of `11`), and a "gear-box" that stores increment values per prime according to the principles of wheel factorization, but operating semi-independently, to reduce space of storing the full wheel.
|
111
|
-
|
112
|
-
Beyond this, we gain a functional advantage of a square-root over a more naive approach, by setting the brute force guessing range only between the highest prime in wheel factorization and the (modular) square root of the number to factor: if the number is semiprime, there is exactly one correct answer in this range, but including both factors in the range to search would cost us the square root advantage.
|
113
|
-
|
114
|
-
Factoring this way is surprisingly easy to distribute: basically 0 network communication is needed to coordinate an arbitrarily high amount of parallelism to factor a single number. Each brute-force trial division instance is effectively 100% independent of all others (i.e. entirely "embarrassingly parallel"), and these guesses can seed independent Gaussian elimination matrices, so `FindAFactor` offers an extremely simply interface that allows work to be split between an arbitrarily high number of nodes with absolutely no network communication at all. In terms of incentives of those running different, cooperating nodes in the context of this specific number of integer factoring, all one ultimately cares about is knowing the correct factorization answer _by any means._ For pratical applications, there is no point at all in factoring a number whose factors are already known. When a hypothetical answer is forwarded to the (0-communication) "network" of collaborating nodes, _it is trivial to check whether the answer is correct_ (such as by simply entering the multiplication and equality check with the original number into a Python shell console)! Hence, collaborating node operators only need to trust that all participants in the "network" are actually performing their alloted segment of guesses and would actually communicate the correct answer to the entire group of collaborating nodes if any specific invidual happened to find the answer, but any purported answer is still trivial to verify.
|
115
|
-
|
116
|
-
**Special thanks to OpenAI GPT "Elara," for indicated region of contributed code!**
|
@@ -1,8 +0,0 @@
|
|
1
|
-
_find_a_factor.cpython-313-darwin.so,sha256=RXlZfzOO2qU8Rffn9El5MTP4xZRiDr2JSy-zCdw_K4Y,850488
|
2
|
-
FindAFactor/__init__.py,sha256=z12lYiLTSXmc8FpKk4tqkSADlHxEV-NqWyA1d5OuQAQ,40
|
3
|
-
FindAFactor/find_a_factor.py,sha256=lIjPkOwcyDtxRj1IZRfsm5nXNEw7dMGJ7MNgykYvSh8,2027
|
4
|
-
FindAFactor-3.7.0.dist-info/LICENSE,sha256=kM5ErD_w66mShD_pmEXez6Evb2_MTLRHykc0qdUWEFY,1085
|
5
|
-
FindAFactor-3.7.0.dist-info/METADATA,sha256=YojLTXbnB_yantxB4yoCni4pwqo22IdY7V9HXJPbOPg,12598
|
6
|
-
FindAFactor-3.7.0.dist-info/WHEEL,sha256=8MDYB8qOpICHXsmvikvrTDt0NBN7mgF9tE1rvEyJ6WE,109
|
7
|
-
FindAFactor-3.7.0.dist-info/top_level.txt,sha256=WoOrEcqIwo8A96WXAtimPshsFZfT5d00SvMC6rVKAn0,27
|
8
|
-
FindAFactor-3.7.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|