Python-based Enigma.
Project description
myenigma
Python-based Enigma.
Install
pip install myenigma
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
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
myenigma-2.0.1.tar.gz
(9.9 kB
view details)
Built Distribution
myenigma-2.0.1-py3-none-any.whl
(11.5 kB
view details)
File details
Details for the file myenigma-2.0.1.tar.gz
.
File metadata
- Download URL: myenigma-2.0.1.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cebaff65d3b470f79e33a86c128c3b98bc89d5c4d2104ba5d34b58f6cf35e18b |
|
MD5 | d84d900c0586ed756e7a0970b1a1105d |
|
BLAKE2b-256 | 1495dafb7d8a4efaa185e68f4f74b9c2694c4a3754f7accc50e78b236f37ea25 |
File details
Details for the file myenigma-2.0.1-py3-none-any.whl
.
File metadata
- Download URL: myenigma-2.0.1-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4c2e0263c754f1fbaf2e55ec21b26c2767f931a4706dfbe65838be61f74b6f4 |
|
MD5 | 30ee22e74dfe1e493394b4aceb52ec37 |
|
BLAKE2b-256 | 7b6386e3b3c2fe92a41f9e5e1f901c8949b9937f7397612a78fc0c0854d0c231 |