toycrypto 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- toycrypto-0.1.0/.gitignore +160 -0
- toycrypto-0.1.0/.vscode/settings.json +16 -0
- toycrypto-0.1.0/.vscode/spellright.dict +4 -0
- toycrypto-0.1.0/LICENSE.txt +9 -0
- toycrypto-0.1.0/PKG-INFO +138 -0
- toycrypto-0.1.0/README.md +109 -0
- toycrypto-0.1.0/dev-requirements.txt +4 -0
- toycrypto-0.1.0/mypy.ini +10 -0
- toycrypto-0.1.0/pyproject.toml +102 -0
- toycrypto-0.1.0/requirements.txt +6 -0
- toycrypto-0.1.0/ruff.toml +2 -0
- toycrypto-0.1.0/src/primefac.pyi +64 -0
- toycrypto-0.1.0/src/toy_crypto/__about__.py +4 -0
- toycrypto-0.1.0/src/toy_crypto/__init__.py +5 -0
- toycrypto-0.1.0/src/toy_crypto/birthday.py +126 -0
- toycrypto-0.1.0/src/toy_crypto/ec.py +353 -0
- toycrypto-0.1.0/src/toy_crypto/nt.py +377 -0
- toycrypto-0.1.0/src/toy_crypto/rand.py +73 -0
- toycrypto-0.1.0/src/toy_crypto/redundent.py +647 -0
- toycrypto-0.1.0/src/toy_crypto/rsa.py +103 -0
- toycrypto-0.1.0/src/toy_crypto/types.py +21 -0
- toycrypto-0.1.0/src/toy_crypto/utils.py +24 -0
- toycrypto-0.1.0/src/toy_crypto/vigenere.py +181 -0
- toycrypto-0.1.0/tests/CHANGELOG.md +11 -0
- toycrypto-0.1.0/tests/__init__.py +10 -0
- toycrypto-0.1.0/tests/ec_test_data.sage +43 -0
- toycrypto-0.1.0/tests/test_birthday.py +211 -0
- toycrypto-0.1.0/tests/test_ec.py +232 -0
- toycrypto-0.1.0/tests/test_nt.py +282 -0
- toycrypto-0.1.0/tests/test_rand.py +69 -0
- toycrypto-0.1.0/tests/test_rsa.py +218 -0
- toycrypto-0.1.0/tests/test_utils.py +20 -0
- toycrypto-0.1.0/tests/test_vigenere.py +103 -0
- toycrypto-0.1.0/tests/timing_sieve.py +48 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# poetry
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
102
|
+
#poetry.lock
|
|
103
|
+
|
|
104
|
+
# pdm
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
106
|
+
#pdm.lock
|
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
108
|
+
# in version control.
|
|
109
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
110
|
+
.pdm.toml
|
|
111
|
+
|
|
112
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
113
|
+
__pypackages__/
|
|
114
|
+
|
|
115
|
+
# Celery stuff
|
|
116
|
+
celerybeat-schedule
|
|
117
|
+
celerybeat.pid
|
|
118
|
+
|
|
119
|
+
# SageMath parsed files
|
|
120
|
+
*.sage.py
|
|
121
|
+
|
|
122
|
+
# Environments
|
|
123
|
+
.env
|
|
124
|
+
.venv
|
|
125
|
+
env/
|
|
126
|
+
venv/
|
|
127
|
+
ENV/
|
|
128
|
+
env.bak/
|
|
129
|
+
venv.bak/
|
|
130
|
+
|
|
131
|
+
# Spyder project settings
|
|
132
|
+
.spyderproject
|
|
133
|
+
.spyproject
|
|
134
|
+
|
|
135
|
+
# Rope project settings
|
|
136
|
+
.ropeproject
|
|
137
|
+
|
|
138
|
+
# mkdocs documentation
|
|
139
|
+
/site
|
|
140
|
+
|
|
141
|
+
# mypy
|
|
142
|
+
.mypy_cache/
|
|
143
|
+
.dmypy.json
|
|
144
|
+
dmypy.json
|
|
145
|
+
|
|
146
|
+
# Pyre type checker
|
|
147
|
+
.pyre/
|
|
148
|
+
|
|
149
|
+
# pytype static type analyzer
|
|
150
|
+
.pytype/
|
|
151
|
+
|
|
152
|
+
# Cython debug symbols
|
|
153
|
+
cython_debug/
|
|
154
|
+
|
|
155
|
+
# PyCharm
|
|
156
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
157
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
158
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
159
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
160
|
+
#.idea/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"python.testing.pytestArgs": [
|
|
3
|
+
"."
|
|
4
|
+
],
|
|
5
|
+
"python.testing.unittestEnabled": false,
|
|
6
|
+
"python.testing.pytestEnabled": true,
|
|
7
|
+
"spellright.language": [
|
|
8
|
+
"en"
|
|
9
|
+
],
|
|
10
|
+
"spellright.documentTypes": [
|
|
11
|
+
"markdown",
|
|
12
|
+
"latex",
|
|
13
|
+
"plaintext",
|
|
14
|
+
"python"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present Jeffrey Goldberg <jeffrey@goldmark.org>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
toycrypto-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: toycrypto
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Some toy cryptographic modules and related tools that should never, ever be used anything over than demonstation purposes.
|
|
5
|
+
Project-URL: Documentation, https://github.com/unknown/toy-crypto-math#readme
|
|
6
|
+
Project-URL: Issues, https://github.com/unknown/toy-crypto-math/issues
|
|
7
|
+
Project-URL: Source, https://github.com/unknown/toy-crypto-math
|
|
8
|
+
Author-email: Jeffrey Goldberg <jeffrey@goldmark.org>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE.txt
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Education
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
21
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
23
|
+
Classifier: Topic :: Security :: Cryptography
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.11
|
|
26
|
+
Requires-Dist: bitarray>=2.9.2
|
|
27
|
+
Requires-Dist: primefac>=2.0.12
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# Toy cryptographic utilities
|
|
31
|
+
|
|
32
|
+
[](http://mypy-lang.org/)
|
|
33
|
+
[](https://docs.astral.sh/ruff/)
|
|
34
|
+
[](https://hatch.pypa.io/latest/)
|
|
35
|
+
[](https://github.com/jpgoldberg/toy-crypto-math/blob/main/LICENSE.txt)
|
|
36
|
+
|
|
37
|
+
----
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
This is (almost certainly) not the package you are looking for.
|
|
41
|
+
|
|
42
|
+
The material here is meant for learning purposes only, often my own learning.
|
|
43
|
+
Do not use it for anything else. And if you do, understand that it focuses on what
|
|
44
|
+
I am trying to illustrate or learn.
|
|
45
|
+
It may not always be correct, and it is not coded with safely in mind.
|
|
46
|
+
|
|
47
|
+
- Use [pyca] if you need to use cryptographic tools in Python.
|
|
48
|
+
- Use [SageMath], [sympy], or [primefac] if you want to play with some of the mathematics of some things underlying Cryptography in
|
|
49
|
+
a Python-like environment.
|
|
50
|
+
|
|
51
|
+
[pyca]: https://cryptography.io
|
|
52
|
+
[SageMath]: https://doc.sagemath.org/
|
|
53
|
+
[sympy]: https://www.sympy.org/en/
|
|
54
|
+
[primefac]: https://pypi.org/project/primefac/
|
|
55
|
+
[PyPi]: https://pypi.org/
|
|
56
|
+
|
|
57
|
+
## Table of Contents
|
|
58
|
+
|
|
59
|
+
- [Toy cryptographic utilities](#toy-cryptographic-utilities)
|
|
60
|
+
- [Table of Contents](#table-of-contents)
|
|
61
|
+
- [Motivation](#motivation)
|
|
62
|
+
- [Installation](#installation)
|
|
63
|
+
- [If you must](#if-you-must)
|
|
64
|
+
- [Usage](#usage)
|
|
65
|
+
- [License](#license)
|
|
66
|
+
|
|
67
|
+
## Motivation
|
|
68
|
+
|
|
69
|
+
This package is almost certainly not the package you are looking for.
|
|
70
|
+
Instead, [pyca] or [SageMath] will better suite your needs.
|
|
71
|
+
I created it to meet a number of my own idiosyncratic needs.
|
|
72
|
+
|
|
73
|
+
- I don't have the flexibility of Python version that I may want when using [SageMath].
|
|
74
|
+
|
|
75
|
+
For example, I want to have access to something that behaves a bit like SageMath's `factor()`
|
|
76
|
+
or the ability to play with elliptic curves without having do everything in Sage.
|
|
77
|
+
Perhaps when [sagemath-standard](https://pypi.org/project/sagemath-standard/) quickly becomes available for the latest Python versions, I won't need to have my own (failable and incomplete) pure Python substitutes for some things I need.
|
|
78
|
+
|
|
79
|
+
- I sometimes talk about these algorithms for teaching purposes. Having pure Python versions allows me to present these.
|
|
80
|
+
|
|
81
|
+
Proper cryptographic packages, like [pyca],
|
|
82
|
+
|
|
83
|
+
- Correctly obscure the lower level primitives I may wish to exhibit;
|
|
84
|
+
- Correctly prevent use of unsafe parameters such as small keys;
|
|
85
|
+
- Correctly involve a lot of abstractions in the calls to the concealed primitives.
|
|
86
|
+
|
|
87
|
+
Those features, essential for something to be used, are not great for expository discussion.
|
|
88
|
+
|
|
89
|
+
- Some of these I created or copied for my own learning purposes.
|
|
90
|
+
|
|
91
|
+
- I have a number of "good enough" (for my purposes) implementations of things that I want to reuse.
|
|
92
|
+
|
|
93
|
+
For example, Birthday collision calculations are things I occasionally want, and I don't want to hunt for wherever I have something like that written or rewrite it yet again.
|
|
94
|
+
Likewise, I wouldn't be surprised if I'm written the extended GCD algorithm more than a dozen times
|
|
95
|
+
(not all in Python), and so would like to have at least the Python version in one place
|
|
96
|
+
|
|
97
|
+
- I want to use cryptographic examples in Jupyter Notebooks.
|
|
98
|
+
|
|
99
|
+
I also want them to be _reproducible_, which is why I am making this public.
|
|
100
|
+
|
|
101
|
+
## Installation
|
|
102
|
+
|
|
103
|
+
Don't. If you need to do cryptography in Python use [pyca].
|
|
104
|
+
|
|
105
|
+
### If you must
|
|
106
|
+
|
|
107
|
+
Once I've published this to [PyPi], you will be able to install it with
|
|
108
|
+
|
|
109
|
+
```console
|
|
110
|
+
pip install toycrypto
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Until this is released on PyPi, you will just have to install from this source.
|
|
114
|
+
|
|
115
|
+
## Usage
|
|
116
|
+
|
|
117
|
+
This is erratically documented at best, a combination of `pydoc` and reading the source it what you will need.
|
|
118
|
+
|
|
119
|
+
The import namespace is `toy_crypto`
|
|
120
|
+
|
|
121
|
+
An example might be something like this,
|
|
122
|
+
using the `factor` function from the Number Theory (nt) module.
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from toy_crypto.nt import factor
|
|
126
|
+
|
|
127
|
+
c = 9159288649
|
|
128
|
+
f = factor(c)
|
|
129
|
+
|
|
130
|
+
assert f == [(11, 2), (5483, 1), (104243, 1)]
|
|
131
|
+
assert str(f) == '11^2 * 5483 * 104243'
|
|
132
|
+
assert f.n == c
|
|
133
|
+
assert f.phi == 62860010840
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
`toy-crypto-math` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Toy cryptographic utilities
|
|
2
|
+
|
|
3
|
+
[](http://mypy-lang.org/)
|
|
4
|
+
[](https://docs.astral.sh/ruff/)
|
|
5
|
+
[](https://hatch.pypa.io/latest/)
|
|
6
|
+
[](https://github.com/jpgoldberg/toy-crypto-math/blob/main/LICENSE.txt)
|
|
7
|
+
|
|
8
|
+
----
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
This is (almost certainly) not the package you are looking for.
|
|
12
|
+
|
|
13
|
+
The material here is meant for learning purposes only, often my own learning.
|
|
14
|
+
Do not use it for anything else. And if you do, understand that it focuses on what
|
|
15
|
+
I am trying to illustrate or learn.
|
|
16
|
+
It may not always be correct, and it is not coded with safely in mind.
|
|
17
|
+
|
|
18
|
+
- Use [pyca] if you need to use cryptographic tools in Python.
|
|
19
|
+
- Use [SageMath], [sympy], or [primefac] if you want to play with some of the mathematics of some things underlying Cryptography in
|
|
20
|
+
a Python-like environment.
|
|
21
|
+
|
|
22
|
+
[pyca]: https://cryptography.io
|
|
23
|
+
[SageMath]: https://doc.sagemath.org/
|
|
24
|
+
[sympy]: https://www.sympy.org/en/
|
|
25
|
+
[primefac]: https://pypi.org/project/primefac/
|
|
26
|
+
[PyPi]: https://pypi.org/
|
|
27
|
+
|
|
28
|
+
## Table of Contents
|
|
29
|
+
|
|
30
|
+
- [Toy cryptographic utilities](#toy-cryptographic-utilities)
|
|
31
|
+
- [Table of Contents](#table-of-contents)
|
|
32
|
+
- [Motivation](#motivation)
|
|
33
|
+
- [Installation](#installation)
|
|
34
|
+
- [If you must](#if-you-must)
|
|
35
|
+
- [Usage](#usage)
|
|
36
|
+
- [License](#license)
|
|
37
|
+
|
|
38
|
+
## Motivation
|
|
39
|
+
|
|
40
|
+
This package is almost certainly not the package you are looking for.
|
|
41
|
+
Instead, [pyca] or [SageMath] will better suite your needs.
|
|
42
|
+
I created it to meet a number of my own idiosyncratic needs.
|
|
43
|
+
|
|
44
|
+
- I don't have the flexibility of Python version that I may want when using [SageMath].
|
|
45
|
+
|
|
46
|
+
For example, I want to have access to something that behaves a bit like SageMath's `factor()`
|
|
47
|
+
or the ability to play with elliptic curves without having do everything in Sage.
|
|
48
|
+
Perhaps when [sagemath-standard](https://pypi.org/project/sagemath-standard/) quickly becomes available for the latest Python versions, I won't need to have my own (failable and incomplete) pure Python substitutes for some things I need.
|
|
49
|
+
|
|
50
|
+
- I sometimes talk about these algorithms for teaching purposes. Having pure Python versions allows me to present these.
|
|
51
|
+
|
|
52
|
+
Proper cryptographic packages, like [pyca],
|
|
53
|
+
|
|
54
|
+
- Correctly obscure the lower level primitives I may wish to exhibit;
|
|
55
|
+
- Correctly prevent use of unsafe parameters such as small keys;
|
|
56
|
+
- Correctly involve a lot of abstractions in the calls to the concealed primitives.
|
|
57
|
+
|
|
58
|
+
Those features, essential for something to be used, are not great for expository discussion.
|
|
59
|
+
|
|
60
|
+
- Some of these I created or copied for my own learning purposes.
|
|
61
|
+
|
|
62
|
+
- I have a number of "good enough" (for my purposes) implementations of things that I want to reuse.
|
|
63
|
+
|
|
64
|
+
For example, Birthday collision calculations are things I occasionally want, and I don't want to hunt for wherever I have something like that written or rewrite it yet again.
|
|
65
|
+
Likewise, I wouldn't be surprised if I'm written the extended GCD algorithm more than a dozen times
|
|
66
|
+
(not all in Python), and so would like to have at least the Python version in one place
|
|
67
|
+
|
|
68
|
+
- I want to use cryptographic examples in Jupyter Notebooks.
|
|
69
|
+
|
|
70
|
+
I also want them to be _reproducible_, which is why I am making this public.
|
|
71
|
+
|
|
72
|
+
## Installation
|
|
73
|
+
|
|
74
|
+
Don't. If you need to do cryptography in Python use [pyca].
|
|
75
|
+
|
|
76
|
+
### If you must
|
|
77
|
+
|
|
78
|
+
Once I've published this to [PyPi], you will be able to install it with
|
|
79
|
+
|
|
80
|
+
```console
|
|
81
|
+
pip install toycrypto
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Until this is released on PyPi, you will just have to install from this source.
|
|
85
|
+
|
|
86
|
+
## Usage
|
|
87
|
+
|
|
88
|
+
This is erratically documented at best, a combination of `pydoc` and reading the source it what you will need.
|
|
89
|
+
|
|
90
|
+
The import namespace is `toy_crypto`
|
|
91
|
+
|
|
92
|
+
An example might be something like this,
|
|
93
|
+
using the `factor` function from the Number Theory (nt) module.
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from toy_crypto.nt import factor
|
|
97
|
+
|
|
98
|
+
c = 9159288649
|
|
99
|
+
f = factor(c)
|
|
100
|
+
|
|
101
|
+
assert f == [(11, 2), (5483, 1), (104243, 1)]
|
|
102
|
+
assert str(f) == '11^2 * 5483 * 104243'
|
|
103
|
+
assert f.n == c
|
|
104
|
+
assert f.phi == 62860010840
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
`toy-crypto-math` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
toycrypto-0.1.0/mypy.ini
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "toycrypto"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = 'Some toy cryptographic modules and related tools that should never, ever be used anything over than demonstation purposes.'
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
keywords = []
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Jeffrey Goldberg", email = "jeffrey@goldmark.org" },
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Programming Language :: Python",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Programming Language :: Python :: Implementation :: CPython",
|
|
23
|
+
"Programming Language :: Python :: Implementation :: PyPy",
|
|
24
|
+
"Intended Audience :: Developers",
|
|
25
|
+
"Intended Audience :: Education",
|
|
26
|
+
"License :: OSI Approved :: MIT License",
|
|
27
|
+
"Operating System :: OS Independent",
|
|
28
|
+
"Topic :: Scientific/Engineering :: Mathematics",
|
|
29
|
+
"Topic :: Security :: Cryptography",
|
|
30
|
+
"Typing :: Typed",
|
|
31
|
+
]
|
|
32
|
+
dependencies = [
|
|
33
|
+
"primefac >= 2.0.12",
|
|
34
|
+
"bitarray >= 2.9.2"
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Documentation = "https://github.com/unknown/toy-crypto-math#readme"
|
|
39
|
+
Issues = "https://github.com/unknown/toy-crypto-math/issues"
|
|
40
|
+
Source = "https://github.com/unknown/toy-crypto-math"
|
|
41
|
+
|
|
42
|
+
[tool.hatch.version]
|
|
43
|
+
path = "src/toy_crypto/__about__.py"
|
|
44
|
+
|
|
45
|
+
[tool.hatch.build.targets.wheel]
|
|
46
|
+
packages = ["src/toy_crypto"]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
[tool.hatch.envs.default]
|
|
50
|
+
dependencies = [
|
|
51
|
+
"coverage[toml]>=6.5",
|
|
52
|
+
"pytest",
|
|
53
|
+
"ruff",
|
|
54
|
+
"mypy>=1.11",
|
|
55
|
+
]
|
|
56
|
+
[tool.hatch.envs.default.scripts]
|
|
57
|
+
test = "pytest {args:tests}"
|
|
58
|
+
test-cov = "coverage run -m pytest {args:tests}"
|
|
59
|
+
cov-report = [
|
|
60
|
+
"- coverage combine",
|
|
61
|
+
"coverage report",
|
|
62
|
+
]
|
|
63
|
+
cov = [
|
|
64
|
+
"test-cov",
|
|
65
|
+
"cov-report",
|
|
66
|
+
]
|
|
67
|
+
lint = "ruff check {args:src/toy_crypto tests}"
|
|
68
|
+
|
|
69
|
+
[[tool.hatch.envs.all.matrix]]
|
|
70
|
+
python = ["3.11", "3.12"]
|
|
71
|
+
|
|
72
|
+
[tool.hatch.envs.types]
|
|
73
|
+
dependencies = [
|
|
74
|
+
"mypy>=1.11",
|
|
75
|
+
]
|
|
76
|
+
[tool.hatch.envs.types.scripts]
|
|
77
|
+
check = "mypy --install-types --non-interactive {args:src/toy_crypto tests}"
|
|
78
|
+
|
|
79
|
+
[tool.coverage.run]
|
|
80
|
+
source_pkgs = ["toy_crypto", "tests"]
|
|
81
|
+
branch = true
|
|
82
|
+
parallel = true
|
|
83
|
+
omit = [
|
|
84
|
+
"src/toy_crypto/__about__.py",
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
[tool.coverage.paths]
|
|
88
|
+
toy_crypto = ["src/toy_crypto", "*/toy-crypto-math/src/toy_crypto"]
|
|
89
|
+
tests = ["tests", "*/toy-crypto-math/tests"]
|
|
90
|
+
|
|
91
|
+
[tool.coverage.report]
|
|
92
|
+
exclude_lines = [
|
|
93
|
+
"no cov",
|
|
94
|
+
"if __name__ == .__main__.:",
|
|
95
|
+
"if TYPE_CHECKING:",
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
[tool.pytest.ini_options]
|
|
99
|
+
markers = [
|
|
100
|
+
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
|
|
101
|
+
"statistical: marks tests of a statistical nature (deselect with '-m \"not statistical\"')",
|
|
102
|
+
]
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from collections.abc import Generator
|
|
3
|
+
from typing import Callable, Optional
|
|
4
|
+
|
|
5
|
+
version: str
|
|
6
|
+
|
|
7
|
+
# def primegen(limit=...) -> Generator[Incomplete, Incomplete, Incomplete]: ...
|
|
8
|
+
# def ilog(x, b): ...
|
|
9
|
+
|
|
10
|
+
def modinv(a: int, m: int) -> int: ...
|
|
11
|
+
def introot(n: int, r: int = 2) -> int: ...
|
|
12
|
+
def ispower(n: int, r: int = 0) -> Optional[tuple[int, int] | int]: ...
|
|
13
|
+
|
|
14
|
+
# def jacobi(a, n): ...
|
|
15
|
+
|
|
16
|
+
def isprime(
|
|
17
|
+
n: int,
|
|
18
|
+
tb: tuple[int, ...] = (
|
|
19
|
+
3,
|
|
20
|
+
5,
|
|
21
|
+
7,
|
|
22
|
+
11,
|
|
23
|
+
13,
|
|
24
|
+
17,
|
|
25
|
+
19,
|
|
26
|
+
23,
|
|
27
|
+
29,
|
|
28
|
+
31,
|
|
29
|
+
37,
|
|
30
|
+
41,
|
|
31
|
+
43,
|
|
32
|
+
47,
|
|
33
|
+
53,
|
|
34
|
+
59,
|
|
35
|
+
),
|
|
36
|
+
) -> bool: ...
|
|
37
|
+
|
|
38
|
+
# def pollardrho_brent(n, verbose: bool = False): ...
|
|
39
|
+
# def pollard_pm1(n, B1: int = 100, B2: int = 1000, verbose: bool = False): ...
|
|
40
|
+
# def mlucas(v, a, n): ...
|
|
41
|
+
# def williams_pp1(n, verbose: bool = False): ...
|
|
42
|
+
# def ecadd(p1, p2, p0, n): ...
|
|
43
|
+
# def ecdub(p, A, n): ...
|
|
44
|
+
# def ecmul(m, p, A, n): ...
|
|
45
|
+
# def secm(n, B1, B2, seed): ...
|
|
46
|
+
# def ecmparams(n) -> Generator[Incomplete, None, None]: ...
|
|
47
|
+
# def ecm(n, paramseq=..., nprocs: int = 1, verbose: bool = False): ...
|
|
48
|
+
|
|
49
|
+
def sqrtmod_prime(a: int, p: int) -> int: ...
|
|
50
|
+
|
|
51
|
+
# def siqs(n, verbose: bool = False): ...
|
|
52
|
+
# def multifactor(n, methods=..., verbose: bool = False): ...
|
|
53
|
+
|
|
54
|
+
def primefac(
|
|
55
|
+
n: int,
|
|
56
|
+
trial: int = 1000,
|
|
57
|
+
rho: int = 42000,
|
|
58
|
+
verbose: bool = False,
|
|
59
|
+
methods: Callable[[int, Incomplete], int] = ...,
|
|
60
|
+
) -> Generator[int, None, None]: ...
|
|
61
|
+
|
|
62
|
+
# def rpn(instr) -> Generator[Incomplete, None, None]: ...
|
|
63
|
+
|
|
64
|
+
usage: str
|