transcrypto 1.0.2__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.
- transcrypto-1.0.2/LICENSE +177 -0
- transcrypto-1.0.2/PKG-INFO +147 -0
- transcrypto-1.0.2/README.md +129 -0
- transcrypto-1.0.2/pyproject.toml +57 -0
- transcrypto-1.0.2/setup.cfg +4 -0
- transcrypto-1.0.2/src/transcrypto/__init__.py +0 -0
- transcrypto-1.0.2/src/transcrypto/py.typed +0 -0
- transcrypto-1.0.2/src/transcrypto/transcrypto.py +294 -0
- transcrypto-1.0.2/src/transcrypto.egg-info/PKG-INFO +147 -0
- transcrypto-1.0.2/src/transcrypto.egg-info/SOURCES.txt +10 -0
- transcrypto-1.0.2/src/transcrypto.egg-info/dependency_links.txt +1 -0
- transcrypto-1.0.2/src/transcrypto.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: transcrypto
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: Basic crypto primitives, not intended for actual use, but as a companion to --Criptografia, Métodos e Algoritmos--
|
|
5
|
+
Author-email: Daniel Balparda <balparda@github.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/balparda/transcrypto
|
|
8
|
+
Project-URL: PyPI, https://pypi.org/project/transcrypto/
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Topic :: Utilities
|
|
13
|
+
Classifier: Topic :: Security :: Cryptography
|
|
14
|
+
Requires-Python: >=3.13.5
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# TransCrypto
|
|
20
|
+
|
|
21
|
+
Basic crypto primitives, not intended for actual use, but as a companion to "Criptografia, Métodos e Algoritmos".
|
|
22
|
+
|
|
23
|
+
Started in July/2025, by Daniel Balparda. Since version 1.0.2 it is PyPI package:
|
|
24
|
+
|
|
25
|
+
<https://pypi.org/project/transcrypto/>
|
|
26
|
+
|
|
27
|
+
## License
|
|
28
|
+
|
|
29
|
+
Copyright 2025 Daniel Balparda <balparda@github.com>
|
|
30
|
+
|
|
31
|
+
Licensed under the ***Apache License, Version 2.0*** (the "License"); you may not use this file except in compliance with the License. You may obtain a [copy of the License here](http://www.apache.org/licenses/LICENSE-2.0).
|
|
32
|
+
|
|
33
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
34
|
+
|
|
35
|
+
## Use
|
|
36
|
+
|
|
37
|
+
### Install
|
|
38
|
+
|
|
39
|
+
To use in your project just do:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
pip3 install transcrypto
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
and then `from transcrypto import transcrypto` for using it.
|
|
46
|
+
|
|
47
|
+
### TODO
|
|
48
|
+
|
|
49
|
+
TODO: explain module...
|
|
50
|
+
|
|
51
|
+
## Development Instructions
|
|
52
|
+
|
|
53
|
+
### Setup
|
|
54
|
+
|
|
55
|
+
If you want to develop for this project, first install [Poetry](https://python-poetry.org/docs/cli/), but make sure it is like this:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
brew uninstall poetry
|
|
59
|
+
python3.11 -m pip install --user pipx
|
|
60
|
+
python3.11 -m pipx ensurepath
|
|
61
|
+
# re-open terminal
|
|
62
|
+
poetry self add poetry-plugin-export@^1.8 # allows export to requirements.txt (see below)
|
|
63
|
+
poetry config virtualenvs.in-project true # creates venv inside project directory
|
|
64
|
+
poetry config pypi-token.pypi <TOKEN> # add you personal project token
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Now install the project:
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
brew install python@3.13 git
|
|
71
|
+
brew update
|
|
72
|
+
brew upgrade
|
|
73
|
+
brew cleanup -s
|
|
74
|
+
# or on Ubuntu/Debian: sudo apt-get install python3.13-venv git
|
|
75
|
+
|
|
76
|
+
git clone https://github.com/balparda/transcrypto.git transcrypto
|
|
77
|
+
cd transcrypto
|
|
78
|
+
|
|
79
|
+
poetry env use python3.13 # creates the venv
|
|
80
|
+
poetry install --sync # HONOR the project's poetry.lock file, uninstalls stray packages
|
|
81
|
+
poetry env info # no-op: just to check
|
|
82
|
+
|
|
83
|
+
poetry run pytest -vvv
|
|
84
|
+
# or any command as:
|
|
85
|
+
poetry run <any-command>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
To activate like a regular environment do:
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
poetry env activate
|
|
92
|
+
# will print activation command which you next execute, or you can do:
|
|
93
|
+
source .env/bin/activate # if .env is local to the project
|
|
94
|
+
source "$(poetry env info --path)/bin/activate" # for other paths
|
|
95
|
+
|
|
96
|
+
pytest
|
|
97
|
+
|
|
98
|
+
deactivate
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Updating Dependencies
|
|
102
|
+
|
|
103
|
+
To update `poetry.lock` file to more current versions:
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
poetry update # ignores current lock, updates, rewrites `poetry.lock` file
|
|
107
|
+
poetry run pytest
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
To add a new dependency you should:
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
poetry add "pkg>=1.2.3" # regenerates lock, updates env
|
|
114
|
+
# also: "pkg@^1.2.3" = latest 1.* ; "pkg@~1.2.3" = latest 1.2.* ; "pkg@1.2.3" exact
|
|
115
|
+
poetry export --format requirements.txt --without-hashes --output requirements.txt
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
If you added a dependency to `pyproject.toml`:
|
|
119
|
+
|
|
120
|
+
```sh
|
|
121
|
+
poetry run pip3 freeze --all # lists all dependencies pip knows about
|
|
122
|
+
poetry lock # re-lock your dependencies, so `poetry.lock` is regenerated
|
|
123
|
+
poetry install # sync your virtualenv to match the new lock file
|
|
124
|
+
poetry export --format requirements.txt --without-hashes --output requirements.txt
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Creating a New Version
|
|
128
|
+
|
|
129
|
+
```sh
|
|
130
|
+
# bump the version!
|
|
131
|
+
poetry version minor # updates 1.6 to 1.7, for example
|
|
132
|
+
# or:
|
|
133
|
+
poetry version patch # updates 1.6 to 1.6.1
|
|
134
|
+
# or:
|
|
135
|
+
poetry version <version-number>
|
|
136
|
+
# (also updates `pyproject.toml` and `poetry.lock`)
|
|
137
|
+
|
|
138
|
+
# publish to GIT, including a TAG
|
|
139
|
+
git commit -a -m "release version 1.0.2"
|
|
140
|
+
git tag 1.0.2
|
|
141
|
+
git push
|
|
142
|
+
git push --tags
|
|
143
|
+
|
|
144
|
+
# prepare package for PyPI
|
|
145
|
+
poetry build
|
|
146
|
+
poetry publish
|
|
147
|
+
```
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# TransCrypto
|
|
2
|
+
|
|
3
|
+
Basic crypto primitives, not intended for actual use, but as a companion to "Criptografia, Métodos e Algoritmos".
|
|
4
|
+
|
|
5
|
+
Started in July/2025, by Daniel Balparda. Since version 1.0.2 it is PyPI package:
|
|
6
|
+
|
|
7
|
+
<https://pypi.org/project/transcrypto/>
|
|
8
|
+
|
|
9
|
+
## License
|
|
10
|
+
|
|
11
|
+
Copyright 2025 Daniel Balparda <balparda@github.com>
|
|
12
|
+
|
|
13
|
+
Licensed under the ***Apache License, Version 2.0*** (the "License"); you may not use this file except in compliance with the License. You may obtain a [copy of the License here](http://www.apache.org/licenses/LICENSE-2.0).
|
|
14
|
+
|
|
15
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
16
|
+
|
|
17
|
+
## Use
|
|
18
|
+
|
|
19
|
+
### Install
|
|
20
|
+
|
|
21
|
+
To use in your project just do:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
pip3 install transcrypto
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
and then `from transcrypto import transcrypto` for using it.
|
|
28
|
+
|
|
29
|
+
### TODO
|
|
30
|
+
|
|
31
|
+
TODO: explain module...
|
|
32
|
+
|
|
33
|
+
## Development Instructions
|
|
34
|
+
|
|
35
|
+
### Setup
|
|
36
|
+
|
|
37
|
+
If you want to develop for this project, first install [Poetry](https://python-poetry.org/docs/cli/), but make sure it is like this:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
brew uninstall poetry
|
|
41
|
+
python3.11 -m pip install --user pipx
|
|
42
|
+
python3.11 -m pipx ensurepath
|
|
43
|
+
# re-open terminal
|
|
44
|
+
poetry self add poetry-plugin-export@^1.8 # allows export to requirements.txt (see below)
|
|
45
|
+
poetry config virtualenvs.in-project true # creates venv inside project directory
|
|
46
|
+
poetry config pypi-token.pypi <TOKEN> # add you personal project token
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Now install the project:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
brew install python@3.13 git
|
|
53
|
+
brew update
|
|
54
|
+
brew upgrade
|
|
55
|
+
brew cleanup -s
|
|
56
|
+
# or on Ubuntu/Debian: sudo apt-get install python3.13-venv git
|
|
57
|
+
|
|
58
|
+
git clone https://github.com/balparda/transcrypto.git transcrypto
|
|
59
|
+
cd transcrypto
|
|
60
|
+
|
|
61
|
+
poetry env use python3.13 # creates the venv
|
|
62
|
+
poetry install --sync # HONOR the project's poetry.lock file, uninstalls stray packages
|
|
63
|
+
poetry env info # no-op: just to check
|
|
64
|
+
|
|
65
|
+
poetry run pytest -vvv
|
|
66
|
+
# or any command as:
|
|
67
|
+
poetry run <any-command>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
To activate like a regular environment do:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
poetry env activate
|
|
74
|
+
# will print activation command which you next execute, or you can do:
|
|
75
|
+
source .env/bin/activate # if .env is local to the project
|
|
76
|
+
source "$(poetry env info --path)/bin/activate" # for other paths
|
|
77
|
+
|
|
78
|
+
pytest
|
|
79
|
+
|
|
80
|
+
deactivate
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Updating Dependencies
|
|
84
|
+
|
|
85
|
+
To update `poetry.lock` file to more current versions:
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
poetry update # ignores current lock, updates, rewrites `poetry.lock` file
|
|
89
|
+
poetry run pytest
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
To add a new dependency you should:
|
|
93
|
+
|
|
94
|
+
```sh
|
|
95
|
+
poetry add "pkg>=1.2.3" # regenerates lock, updates env
|
|
96
|
+
# also: "pkg@^1.2.3" = latest 1.* ; "pkg@~1.2.3" = latest 1.2.* ; "pkg@1.2.3" exact
|
|
97
|
+
poetry export --format requirements.txt --without-hashes --output requirements.txt
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
If you added a dependency to `pyproject.toml`:
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
poetry run pip3 freeze --all # lists all dependencies pip knows about
|
|
104
|
+
poetry lock # re-lock your dependencies, so `poetry.lock` is regenerated
|
|
105
|
+
poetry install # sync your virtualenv to match the new lock file
|
|
106
|
+
poetry export --format requirements.txt --without-hashes --output requirements.txt
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Creating a New Version
|
|
110
|
+
|
|
111
|
+
```sh
|
|
112
|
+
# bump the version!
|
|
113
|
+
poetry version minor # updates 1.6 to 1.7, for example
|
|
114
|
+
# or:
|
|
115
|
+
poetry version patch # updates 1.6 to 1.6.1
|
|
116
|
+
# or:
|
|
117
|
+
poetry version <version-number>
|
|
118
|
+
# (also updates `pyproject.toml` and `poetry.lock`)
|
|
119
|
+
|
|
120
|
+
# publish to GIT, including a TAG
|
|
121
|
+
git commit -a -m "release version 1.0.2"
|
|
122
|
+
git tag 1.0.2
|
|
123
|
+
git push
|
|
124
|
+
git push --tags
|
|
125
|
+
|
|
126
|
+
# prepare package for PyPI
|
|
127
|
+
poetry build
|
|
128
|
+
poetry publish
|
|
129
|
+
```
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# pyproject.toml (preferred for new projects, PEP 621)
|
|
2
|
+
# Copyright 2025 Daniel Balparda (balparda@github.com)
|
|
3
|
+
# Apache-2.0 license
|
|
4
|
+
|
|
5
|
+
[build-system]
|
|
6
|
+
requires = ["setuptools>=80", "wheel"]
|
|
7
|
+
build-backend = "setuptools.build_meta"
|
|
8
|
+
|
|
9
|
+
[project]
|
|
10
|
+
name = "transcrypto"
|
|
11
|
+
version = "1.0.2"
|
|
12
|
+
description = "Basic crypto primitives, not intended for actual use, but as a companion to --Criptografia, Métodos e Algoritmos--"
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
license = "Apache-2.0"
|
|
15
|
+
license-files = ["LICENSE"]
|
|
16
|
+
authors = [
|
|
17
|
+
{ name = "Daniel Balparda", email = "balparda@github.com" }
|
|
18
|
+
]
|
|
19
|
+
requires-python = ">=3.13.5" # if version changes, remember to change README.md
|
|
20
|
+
classifiers = [ # see: https://pypi.org/classifiers/
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Operating System :: OS Independent",
|
|
24
|
+
"Topic :: Utilities",
|
|
25
|
+
"Topic :: Security :: Cryptography"
|
|
26
|
+
]
|
|
27
|
+
dependencies = [
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://github.com/balparda/transcrypto"
|
|
32
|
+
PyPI = "https://pypi.org/project/transcrypto/"
|
|
33
|
+
|
|
34
|
+
[tool.setuptools]
|
|
35
|
+
package-dir = {"" = "src"} # root package namespace lives in src/
|
|
36
|
+
|
|
37
|
+
[tool.setuptools.packages.find]
|
|
38
|
+
where = ["src"] # auto-discover every importable package inside src/
|
|
39
|
+
include = ["transcrypto*"] # avoid picking up stuff not in "transcrypto"
|
|
40
|
+
|
|
41
|
+
[tool.setuptools.package-data]
|
|
42
|
+
"transcrypto" = ["py.typed"]
|
|
43
|
+
|
|
44
|
+
[tool.poetry.requires-plugins]
|
|
45
|
+
poetry-plugin-export = ">=1.8"
|
|
46
|
+
|
|
47
|
+
[tool.poetry.group.dev.dependencies]
|
|
48
|
+
pylint = "^3.3"
|
|
49
|
+
flake8 = "^7.2"
|
|
50
|
+
pyright = "^1.1"
|
|
51
|
+
pytest = ">=8.4"
|
|
52
|
+
pytest-pythonpath = ">=0.7"
|
|
53
|
+
coverage = ">=7.9"
|
|
54
|
+
tomli = ">=2.2.1"
|
|
55
|
+
|
|
56
|
+
[pytest]
|
|
57
|
+
pythonpath = ["src"]
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
#
|
|
3
|
+
# Copyright 2025 Daniel Balparda (balparda@github.com) - Apache-2.0 license
|
|
4
|
+
#
|
|
5
|
+
"""Balparda's TransCrypto."""
|
|
6
|
+
|
|
7
|
+
import math
|
|
8
|
+
# import pdb
|
|
9
|
+
import random
|
|
10
|
+
from typing import Generator, Optional
|
|
11
|
+
|
|
12
|
+
__author__ = 'balparda@github.com'
|
|
13
|
+
__version__: tuple[int, int, int] = (1, 0, 2) # v1.0.2, 2025-07-22
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
FIRST_60_PRIMES_SORTED: list[int] = [
|
|
17
|
+
2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
|
|
18
|
+
31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
|
|
19
|
+
73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
|
|
20
|
+
127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
|
|
21
|
+
179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
|
|
22
|
+
233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
|
|
23
|
+
]
|
|
24
|
+
FIRST_60_PRIMES: set[int] = set(FIRST_60_PRIMES_SORTED)
|
|
25
|
+
COMPOSITE_60: int = math.prod(FIRST_60_PRIMES_SORTED)
|
|
26
|
+
PRIME_60: int = FIRST_60_PRIMES_SORTED[-1] # 281
|
|
27
|
+
|
|
28
|
+
_MAX_PRIMALITY_SAFETY = 100 # this is an absurd number, just to have a max
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Error(Exception):
|
|
32
|
+
"""TransCrypto exception."""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def GCD(a: int, b: int, /) -> int:
|
|
36
|
+
"""Greatest Common Divisor for `a` and `b`, positive integers.
|
|
37
|
+
|
|
38
|
+
Uses the Euclid method.
|
|
39
|
+
"""
|
|
40
|
+
# test inputs
|
|
41
|
+
if a < 0 or b < 0:
|
|
42
|
+
raise Error(f'negative input: {a=} , {b=}')
|
|
43
|
+
# algo needs to start with a >= b
|
|
44
|
+
if a < b:
|
|
45
|
+
a, b = b, a
|
|
46
|
+
# euclid
|
|
47
|
+
while b:
|
|
48
|
+
r: int = a % b
|
|
49
|
+
a, b = b, r
|
|
50
|
+
return a
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def ExtendedGCD(a: int, b: int, /) -> tuple[int, int, int]:
|
|
54
|
+
"""Greatest Common Divisor Extended for `a` and `b`, positive integers.
|
|
55
|
+
|
|
56
|
+
Uses the Euclid method.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
(gcd, x, y) so that a * x + b * y = gcd
|
|
60
|
+
x and y may be negative integers or zero but won't be both zero.
|
|
61
|
+
"""
|
|
62
|
+
# test inputs
|
|
63
|
+
if a < 0 or b < 0:
|
|
64
|
+
raise Error(f'negative input: {a=} , {b=}')
|
|
65
|
+
# algo needs to start with a >= b (but we remember if we did swap)
|
|
66
|
+
swapped = False
|
|
67
|
+
if a < b:
|
|
68
|
+
a, b = b, a
|
|
69
|
+
swapped = True
|
|
70
|
+
# trivial case
|
|
71
|
+
if not b:
|
|
72
|
+
return (a, 0 if swapped else 1, 1 if swapped else 0)
|
|
73
|
+
# euclid
|
|
74
|
+
x1, x2, y1, y2 = 0, 1, 1, 0
|
|
75
|
+
while b:
|
|
76
|
+
q, r = divmod(a, b)
|
|
77
|
+
x, y = x2 - q * x1, y2 - q * y1
|
|
78
|
+
a, b, x1, x2, y1, y2 = b, r, x, x1, y, y1
|
|
79
|
+
return (a, y2 if swapped else x2, x2 if swapped else y2)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def ModExp(x: int, y: int, m: int, /) -> int:
|
|
83
|
+
"""Modular exponential: returns (x ** y) % m efficiently (can handle huge values)."""
|
|
84
|
+
# test inputs
|
|
85
|
+
if x < 0 or y < 0:
|
|
86
|
+
raise Error(f'negative input: {x=} , {y=}')
|
|
87
|
+
if m < 1:
|
|
88
|
+
raise Error(f'invalid module: {m=}')
|
|
89
|
+
# trivial cases
|
|
90
|
+
if not x:
|
|
91
|
+
return 0
|
|
92
|
+
if not y or x == 1:
|
|
93
|
+
return 1 % m
|
|
94
|
+
if y == 1:
|
|
95
|
+
return x % m
|
|
96
|
+
# now both x > 1 and y > 1
|
|
97
|
+
z: int = 1
|
|
98
|
+
while y:
|
|
99
|
+
y, odd = divmod(y, 2)
|
|
100
|
+
if odd:
|
|
101
|
+
z = (z * x) % m
|
|
102
|
+
x = (x * x) % m
|
|
103
|
+
return z
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def FermatIsPrime(
|
|
107
|
+
n: int, /, *,
|
|
108
|
+
safety: int = 10,
|
|
109
|
+
witnesses: Optional[set[int]] = None) -> bool:
|
|
110
|
+
"""Primality test of `n` by Fermat's algo (n > 0). DO NOT RELY!
|
|
111
|
+
|
|
112
|
+
Will execute Fermat's algo for non-trivial `n` (n > 3 and odd).
|
|
113
|
+
<https://en.wikipedia.org/wiki/Fermat_primality_test>
|
|
114
|
+
|
|
115
|
+
This is for didactical uses only, as it is reasonably easy for this algo to fail
|
|
116
|
+
on simple cases. For example, 8911 will fail for many sets of 10 random witnesses.
|
|
117
|
+
(See <https://en.wikipedia.org/wiki/Carmichael_number> to understand better.)
|
|
118
|
+
Miller-Rabin below (MillerRabinIsPrime) has been tuned to be VERY reliable by default.
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
n (int): Number to test primality
|
|
122
|
+
safety (int, optional): Maximum witnesses to use (only if witnesses is not given)
|
|
123
|
+
witnesses (set[int], optional): If given will use exactly these witnesses, in order
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
False if certainly not prime ; True if (probabilistically) prime
|
|
127
|
+
"""
|
|
128
|
+
# test inputs and test for trivial cases: 1, 2, 3, divisible by 2
|
|
129
|
+
if n < 1:
|
|
130
|
+
raise Error(f'invalid number: {n=}')
|
|
131
|
+
if n in (2, 3):
|
|
132
|
+
return True
|
|
133
|
+
if n == 1 or not n % 2:
|
|
134
|
+
return False
|
|
135
|
+
# n is odd and >= 5 so now we generate witnesses (if needed)
|
|
136
|
+
# degenerate case is: n==5, max_safety==2 => randint(2, 3) => {2, 3}
|
|
137
|
+
if not witnesses:
|
|
138
|
+
max_safety: int = min(n // 2, _MAX_PRIMALITY_SAFETY)
|
|
139
|
+
if safety < 1:
|
|
140
|
+
raise Error(f'out of bounds safety: 1 <= {safety=} <= {max_safety}')
|
|
141
|
+
safety = max_safety if safety > max_safety else safety
|
|
142
|
+
witnesses = set()
|
|
143
|
+
while len(witnesses) < safety:
|
|
144
|
+
witnesses.add(random.randint(2, n - 2))
|
|
145
|
+
# we have our witnesses: do the actual Fermat algo
|
|
146
|
+
for w in sorted(witnesses):
|
|
147
|
+
if not 2 <= w <= (n - 2):
|
|
148
|
+
raise Error(f'out of bounds witness: 2 <= {w=} <= {n - 2}')
|
|
149
|
+
if ModExp(w, n - 1, n) != 1:
|
|
150
|
+
# number is proved to be composite
|
|
151
|
+
return False
|
|
152
|
+
# we declare the number PROBABLY a prime to the limits of this test
|
|
153
|
+
return True
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _MillerRabinWitnesses(n: int, /) -> set[int]: # pylint: disable=too-many-return-statements
|
|
157
|
+
"""Generates a reasonable set of Miller-Rabin witnesses for testing primality of `n`.
|
|
158
|
+
|
|
159
|
+
For n < 3317044064679887385961981 it is precise. That is more than 2**81. See:
|
|
160
|
+
<https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test#Testing_against_small_sets_of_bases>
|
|
161
|
+
|
|
162
|
+
For n >= 3317044064679887385961981 it is probabilistic, but computes an number of witnesses
|
|
163
|
+
that should make the test fail less than once in 2**80 tries (once in 10^25). For all intent and
|
|
164
|
+
purposes it "never" fails.
|
|
165
|
+
"""
|
|
166
|
+
# test inputs
|
|
167
|
+
if n < 5:
|
|
168
|
+
raise Error(f'invalid number: {n=}')
|
|
169
|
+
# for some "smaller" values there is research that shows these sets are always enough
|
|
170
|
+
if n < 2047:
|
|
171
|
+
return {2} # "safety" 1, but 100% coverage
|
|
172
|
+
if n < 9080191:
|
|
173
|
+
return {31, 73} # "safety" 2, but 100% coverage
|
|
174
|
+
if n < 4759123141:
|
|
175
|
+
return {2, 7, 61} # "safety" 3, but 100% coverage
|
|
176
|
+
if n < 2152302898747:
|
|
177
|
+
return set(FIRST_60_PRIMES_SORTED[:5]) # "safety" 5, but 100% coverage
|
|
178
|
+
if n < 341550071728321:
|
|
179
|
+
return set(FIRST_60_PRIMES_SORTED[:7]) # "safety" 7, but 100% coverage
|
|
180
|
+
if n < 18446744073709551616: # 2 ** 64
|
|
181
|
+
return set(FIRST_60_PRIMES_SORTED[:12]) # "safety" 12, but 100% coverage
|
|
182
|
+
if n < 3317044064679887385961981: # > 2 ** 81
|
|
183
|
+
return set(FIRST_60_PRIMES_SORTED[:13]) # "safety" 13, but 100% coverage
|
|
184
|
+
# here n should be greater than 2 ** 81, so safety should be 34 or less
|
|
185
|
+
n_bits: int = n.bit_length()
|
|
186
|
+
assert n_bits >= 82 # "should never happen"
|
|
187
|
+
safety: int = int(math.ceil(0.375 + 1.59 / (0.000590 * n_bits))) if n_bits <= 1700 else 2
|
|
188
|
+
assert 1 < safety <= 34 # "should never happen"
|
|
189
|
+
return set(FIRST_60_PRIMES_SORTED[:safety])
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def _MillerRabinSR(n: int, /) -> tuple[int, int]:
|
|
193
|
+
"""Generates (s, r) where (2 ** s) * r == (n - 1) hold true, for odd n > 5.
|
|
194
|
+
|
|
195
|
+
It should be always true that: s >= 1 and r >= 1 and r is odd.
|
|
196
|
+
"""
|
|
197
|
+
# test inputs
|
|
198
|
+
if n < 5 or not n % 2:
|
|
199
|
+
raise Error(f'invalid odd number: {n=}')
|
|
200
|
+
# divide by 2 until we can't anymore
|
|
201
|
+
s: int = 1
|
|
202
|
+
r: int = (n - 1) // 2
|
|
203
|
+
while not r % 2:
|
|
204
|
+
s += 1
|
|
205
|
+
r //= 2
|
|
206
|
+
# make sure everything checks out and return
|
|
207
|
+
assert 1 <= r <= n and r % 2 # "should never happen"
|
|
208
|
+
return (s, r)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def MillerRabinIsPrime(
|
|
212
|
+
n: int, /, *,
|
|
213
|
+
witnesses: Optional[set[int]] = None) -> bool:
|
|
214
|
+
"""Primality test of `n` by Miller-Rabin's algo (n > 0).
|
|
215
|
+
|
|
216
|
+
Will execute Miller-Rabin's algo for non-trivial `n` (n > 3 and odd).
|
|
217
|
+
<https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test>
|
|
218
|
+
|
|
219
|
+
Args:
|
|
220
|
+
n (int): Number to test primality
|
|
221
|
+
witnesses (set[int], optional): If given will use exactly these witnesses, in order
|
|
222
|
+
|
|
223
|
+
Returns:
|
|
224
|
+
False if certainly not prime ; True if (probabilistically) prime
|
|
225
|
+
"""
|
|
226
|
+
# test inputs and test for trivial cases: 1, 2, 3, divisible by 2
|
|
227
|
+
if n < 1:
|
|
228
|
+
raise Error(f'invalid number: {n=}')
|
|
229
|
+
if n in (2, 3):
|
|
230
|
+
return True
|
|
231
|
+
if n == 1 or not n % 2:
|
|
232
|
+
return False
|
|
233
|
+
# n is odd and >= 5; find s and r so that (2 ** s) * r == (n - 1)
|
|
234
|
+
s, r = _MillerRabinSR(n)
|
|
235
|
+
# do the Miller-Rabin algo
|
|
236
|
+
n_limits: tuple[int, int] = (1, n - 1)
|
|
237
|
+
y: int
|
|
238
|
+
for w in sorted(witnesses if witnesses else _MillerRabinWitnesses(n)):
|
|
239
|
+
if not 2 <= w <= (n - 2):
|
|
240
|
+
raise Error(f'out of bounds witness: 2 <= {w=} <= {n - 2}')
|
|
241
|
+
x: int = ModExp(w, r, n)
|
|
242
|
+
if x not in n_limits:
|
|
243
|
+
for _ in range(s): # s >= 1 so will execute at least once
|
|
244
|
+
y = (x * x) % n
|
|
245
|
+
if y == 1 and x not in n_limits:
|
|
246
|
+
return False # number is proved to be composite
|
|
247
|
+
x = y
|
|
248
|
+
if x != 1:
|
|
249
|
+
return False # number is proved to be composite
|
|
250
|
+
# we declare the number PROBABLY a prime to the limits of this test
|
|
251
|
+
return True
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def PrimeGenerator(start: int) -> Generator[int, None, None]:
|
|
255
|
+
"""Generates all primes from `start` until loop is broken. Tuned for huge numbers."""
|
|
256
|
+
# test inputs and make sure we start at an odd number
|
|
257
|
+
if start < 0:
|
|
258
|
+
raise Error(f'invalid number: {start=}')
|
|
259
|
+
# handle start of sequence manually if needed... because we have here the only EVEN prime...
|
|
260
|
+
if start <= 2:
|
|
261
|
+
yield 2
|
|
262
|
+
start = 3
|
|
263
|
+
# we now focus on odd numbers only and loop forever
|
|
264
|
+
n: int = (start if start % 2 else start + 1) - 2 # n >= 1 always
|
|
265
|
+
while True:
|
|
266
|
+
n += 2 # next odd number
|
|
267
|
+
# is number divisible by (one of the) first 60 primes? test should eliminate 80%+ of candidates
|
|
268
|
+
if n > PRIME_60 and GCD(n, COMPOSITE_60) != 1:
|
|
269
|
+
continue # not prime
|
|
270
|
+
# do the (more expensive) primality test
|
|
271
|
+
if MillerRabinIsPrime(n):
|
|
272
|
+
yield n # found a prime
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def MersennePrimesGenerator(start: int) -> Generator[tuple[int, int, int], None, None]:
|
|
276
|
+
"""Generates all Mersenne prime (2 ** n - 1) exponents from 2**start until loop is broken.
|
|
277
|
+
|
|
278
|
+
<https://en.wikipedia.org/wiki/List_of_Mersenne_primes_and_perfect_numbers>
|
|
279
|
+
|
|
280
|
+
Yields:
|
|
281
|
+
(exponent, mersenne_prime, perfect_number), given some exponent `n` that will be exactly:
|
|
282
|
+
(n, 2 ** n - 1, (2 ** (n - 1)) * (2 ** n - 1))
|
|
283
|
+
"""
|
|
284
|
+
# we now loop forever over prime exponents
|
|
285
|
+
# "The exponents p corresponding to Mersenne primes must themselves be prime."
|
|
286
|
+
for n in PrimeGenerator(start if start >= 1 else 1):
|
|
287
|
+
mersenne: int = 2 ** n - 1
|
|
288
|
+
# is number divisible by (one of the) first 60 primes? test should eliminate 80%+ of candidates
|
|
289
|
+
if mersenne > PRIME_60 and GCD(mersenne, COMPOSITE_60) != 1:
|
|
290
|
+
continue # not prime
|
|
291
|
+
# do the (more expensive) primality test
|
|
292
|
+
if MillerRabinIsPrime(mersenne):
|
|
293
|
+
# found a prime, yield it plus the perfect number associated with it
|
|
294
|
+
yield (n, mersenne, (2 ** (n - 1)) * mersenne)
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: transcrypto
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: Basic crypto primitives, not intended for actual use, but as a companion to --Criptografia, Métodos e Algoritmos--
|
|
5
|
+
Author-email: Daniel Balparda <balparda@github.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/balparda/transcrypto
|
|
8
|
+
Project-URL: PyPI, https://pypi.org/project/transcrypto/
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Topic :: Utilities
|
|
13
|
+
Classifier: Topic :: Security :: Cryptography
|
|
14
|
+
Requires-Python: >=3.13.5
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# TransCrypto
|
|
20
|
+
|
|
21
|
+
Basic crypto primitives, not intended for actual use, but as a companion to "Criptografia, Métodos e Algoritmos".
|
|
22
|
+
|
|
23
|
+
Started in July/2025, by Daniel Balparda. Since version 1.0.2 it is PyPI package:
|
|
24
|
+
|
|
25
|
+
<https://pypi.org/project/transcrypto/>
|
|
26
|
+
|
|
27
|
+
## License
|
|
28
|
+
|
|
29
|
+
Copyright 2025 Daniel Balparda <balparda@github.com>
|
|
30
|
+
|
|
31
|
+
Licensed under the ***Apache License, Version 2.0*** (the "License"); you may not use this file except in compliance with the License. You may obtain a [copy of the License here](http://www.apache.org/licenses/LICENSE-2.0).
|
|
32
|
+
|
|
33
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
34
|
+
|
|
35
|
+
## Use
|
|
36
|
+
|
|
37
|
+
### Install
|
|
38
|
+
|
|
39
|
+
To use in your project just do:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
pip3 install transcrypto
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
and then `from transcrypto import transcrypto` for using it.
|
|
46
|
+
|
|
47
|
+
### TODO
|
|
48
|
+
|
|
49
|
+
TODO: explain module...
|
|
50
|
+
|
|
51
|
+
## Development Instructions
|
|
52
|
+
|
|
53
|
+
### Setup
|
|
54
|
+
|
|
55
|
+
If you want to develop for this project, first install [Poetry](https://python-poetry.org/docs/cli/), but make sure it is like this:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
brew uninstall poetry
|
|
59
|
+
python3.11 -m pip install --user pipx
|
|
60
|
+
python3.11 -m pipx ensurepath
|
|
61
|
+
# re-open terminal
|
|
62
|
+
poetry self add poetry-plugin-export@^1.8 # allows export to requirements.txt (see below)
|
|
63
|
+
poetry config virtualenvs.in-project true # creates venv inside project directory
|
|
64
|
+
poetry config pypi-token.pypi <TOKEN> # add you personal project token
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Now install the project:
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
brew install python@3.13 git
|
|
71
|
+
brew update
|
|
72
|
+
brew upgrade
|
|
73
|
+
brew cleanup -s
|
|
74
|
+
# or on Ubuntu/Debian: sudo apt-get install python3.13-venv git
|
|
75
|
+
|
|
76
|
+
git clone https://github.com/balparda/transcrypto.git transcrypto
|
|
77
|
+
cd transcrypto
|
|
78
|
+
|
|
79
|
+
poetry env use python3.13 # creates the venv
|
|
80
|
+
poetry install --sync # HONOR the project's poetry.lock file, uninstalls stray packages
|
|
81
|
+
poetry env info # no-op: just to check
|
|
82
|
+
|
|
83
|
+
poetry run pytest -vvv
|
|
84
|
+
# or any command as:
|
|
85
|
+
poetry run <any-command>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
To activate like a regular environment do:
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
poetry env activate
|
|
92
|
+
# will print activation command which you next execute, or you can do:
|
|
93
|
+
source .env/bin/activate # if .env is local to the project
|
|
94
|
+
source "$(poetry env info --path)/bin/activate" # for other paths
|
|
95
|
+
|
|
96
|
+
pytest
|
|
97
|
+
|
|
98
|
+
deactivate
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Updating Dependencies
|
|
102
|
+
|
|
103
|
+
To update `poetry.lock` file to more current versions:
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
poetry update # ignores current lock, updates, rewrites `poetry.lock` file
|
|
107
|
+
poetry run pytest
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
To add a new dependency you should:
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
poetry add "pkg>=1.2.3" # regenerates lock, updates env
|
|
114
|
+
# also: "pkg@^1.2.3" = latest 1.* ; "pkg@~1.2.3" = latest 1.2.* ; "pkg@1.2.3" exact
|
|
115
|
+
poetry export --format requirements.txt --without-hashes --output requirements.txt
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
If you added a dependency to `pyproject.toml`:
|
|
119
|
+
|
|
120
|
+
```sh
|
|
121
|
+
poetry run pip3 freeze --all # lists all dependencies pip knows about
|
|
122
|
+
poetry lock # re-lock your dependencies, so `poetry.lock` is regenerated
|
|
123
|
+
poetry install # sync your virtualenv to match the new lock file
|
|
124
|
+
poetry export --format requirements.txt --without-hashes --output requirements.txt
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Creating a New Version
|
|
128
|
+
|
|
129
|
+
```sh
|
|
130
|
+
# bump the version!
|
|
131
|
+
poetry version minor # updates 1.6 to 1.7, for example
|
|
132
|
+
# or:
|
|
133
|
+
poetry version patch # updates 1.6 to 1.6.1
|
|
134
|
+
# or:
|
|
135
|
+
poetry version <version-number>
|
|
136
|
+
# (also updates `pyproject.toml` and `poetry.lock`)
|
|
137
|
+
|
|
138
|
+
# publish to GIT, including a TAG
|
|
139
|
+
git commit -a -m "release version 1.0.2"
|
|
140
|
+
git tag 1.0.2
|
|
141
|
+
git push
|
|
142
|
+
git push --tags
|
|
143
|
+
|
|
144
|
+
# prepare package for PyPI
|
|
145
|
+
poetry build
|
|
146
|
+
poetry publish
|
|
147
|
+
```
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/transcrypto/__init__.py
|
|
5
|
+
src/transcrypto/py.typed
|
|
6
|
+
src/transcrypto/transcrypto.py
|
|
7
|
+
src/transcrypto.egg-info/PKG-INFO
|
|
8
|
+
src/transcrypto.egg-info/SOURCES.txt
|
|
9
|
+
src/transcrypto.egg-info/dependency_links.txt
|
|
10
|
+
src/transcrypto.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
transcrypto
|