myenigma
Python-based Enigma.
A brief tutorial of how to develop it (in Chinese)
Install
pip install myenigma
Only supports Python 3.10 or above.
Usage
Import
from myenigma import Enigma
The package also contains some sample plate:
from myenigma.sample_plate.rotor import rotor_i, rotor_ii, rotor_iii
from myenigma.sample_plate.reflector import reflector_b
Defining
Make sure the rotors are from right to left:
e = Enigma([rotor_iii(), rotor_ii(), rotor_i()], reflector_b())
Encryption / Decryption
Just input:
assert e.input('HELLOWORLDBYTHEAUTHOROFTHISPACKAGEDINGJUNYAO') == 'ILBDAAMTAZIJNXSCSIJJPDDWZBRCCUPGQXGRJXQOFGHL'
And change the positions of the rotors (Defaults to all origin):
e.set_position()
assert e.input('ILBDAAMTAZIJNXSCSIJJPDDWZBRCCUPGQXGRJXQOFGHL') == 'HELLOWORLDBYTHEAUTHOROFTHISPACKAGEDINGJUNYAO'
Number starts from 0, and also from right to left. You can also use letter:
e.set_position(3, 12, 21)
assert e.input('HELLOWORLDBYTHEAUTHOROFTHISPACKAGEDINGJUNYAO') == 'XTGHAGDIVUPGBZVQSFMBSGLKVQHQWESYRTSRMOOFGRLE'
e.set_position('D', 12, 21)
assert e.input('XTGHAGDIVUPGBZVQSFMBSGLKVQHQWESYRTSRMOOFGRLE') == 'HELLOWORLDBYTHEAUTHOROFTHISPACKAGEDINGJUNYAO'
Customize
You can freely customize your Enigma. For example, customize the circuits of rotors:
from myenigma.part.plate import Rotor, Reflector
rotor_I = Rotor('EKMFLGDQVZNTOWYHXUSPAIBRCJ', name='Rotor I', turnover='Q')
rotor_II = Rotor('AJDKSIRUXBLHWTMCQGZNPYFVOE', name='Rotor II', turnover='E')
rotor_III = Rotor('BDFHJLCPRTXVZNYEIWGAKMUSQO', name='Rotor III', turnover='V')
reflector_B = Reflector('YRUHQSLDPXNGOKMIEBFZCWVJAT', name='Reflector B')
e_customize = Enigma([rotor_III, rotor_II, rotor_I], reflector_B)
# same as e above
A tiny Enigma:
map_source = 'ASDF'
e_custom_1 = Enigma(
[
Rotor('AFSD', name='I', map_source=map_source),
Rotor('SDAF', name='II', map_source=map_source),
Rotor('DFAS', name='III', map_source=map_source),
],
Reflector('DFAS', name='R', map_source=map_source),
rotate_up=True, rotate_after_type=True
)
assert e_custom_1.input('AA') == 'SD'
e_custom_1.set_position()
assert e_custom_1.input('SD') == 'AA'
And even in other character!
map_source_2 = '甲乙丙丁'
e_custom_2 = Enigma(
[
Rotor('甲丁乙丙', name='I', map_source=map_source_2),
Rotor('乙丙甲丁', name='II', map_source=map_source_2),
Rotor('丙丁甲乙', name='III', map_source=map_source_2),
],
Reflector('丙丁甲乙', name='R', map_source=map_source_2),
rotate_up=True, rotate_after_type=True
)
assert e_custom_2.input('甲甲') == '乙丙'
e_custom_2.set_position()
assert e_custom_2.input('乙丙') == '甲甲'
Plugboard
Plugboard is also supported:
e.plugboard.plug('L', 'M')
e.plugboard.plug('O', 'P')
assert e.input('HELLOWORLDBYTHEAUTHOROFTHISPACKAGEDINGJUNYAO') == 'IMKPJAITPZIJNXSCSIJEOEDWZBRMCUOGQXGRJXQPFGHF'
e.set_position()
assert e.input('IMKPJAITPZIJNXSCSIJEOEDWZBRMCUOGQXGRJXQPFGHF') == 'HELLOWORLDBYTHEAUTHOROFTHISPACKAGEDINGJUNYAO'
e.unplug('L')
e.unplug('P')
Reference
- 恩尼格玛密码机 - 维基百科,自由的百科全书
- Enigma Sim Manual
- Enigma Simulator
- Enigma Rotor and Umkehrwalze Wirings
- 恩尼格玛密码机密码加密/解密 - 一个工具箱 - 好用的在线工具都在这里!
License
MIT License.
Metadata
Release files for myenigma 2.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| myenigma-2.0.2.tar.gz | 10.1 kB | Without provenance | Details for myenigma-2.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| myenigma-2.0.2-py3-none-any.whl | Python 3 | none | any | Details for myenigma-2.0.2-py3-none-any.whl |
Total release size: 21.7 kB
Release files / myenigma-2.0.2.tar.gz
| Download URL | myenigma-2.0.2.tar.gz |
|---|---|
| Size | 10.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7bfc60ead76d614bc6b9ce12505a20982bfd5eae6211e0e0a29c54ca331121f0
|
|
BLAKE2b-256 checksum How to use checksums |
c9078896cb324248435a40b2a8018304af971ee6218f0335e3c5401b284071d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|
Release files / myenigma-2.0.2-py3-none-any.whl
| Download URL | myenigma-2.0.2-py3-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3648d7423724d1d1c32b265bed2493efcbf15769f4ab69371c48fb3cc0cec884
|
|
BLAKE2b-256 checksum How to use checksums |
616892cfaae42d609d25c5d0330389696ea37098fa8bcaa2b0f4069ebd7b8ff7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|
Security for myenigma 2.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.