convez.ai
PluginSegurançaIntermediário
denismaggior8

Enigma Python

denismaggior8/enigma-python

Emulador fiel de máquinas Enigma com suporte a múltiplos modelos

Ver no GitHub
BomPluginScore · de 0 a 100

Biblioteca Python que emula fielmente diferentes modelos de máquinas Enigma usadas na Segunda Guerra Mundial. Permite configurar rotores, refletores e posições de anel para criptografar e descriptografar mensagens com precisão histórica, verificada contra dados autênticos.

Instalação

$npx convez-ai denismaggior8/enigma-python

1 comando no terminal: detecta o formato do repositório (marketplace ou plugin avulso) e instala via Claude Code. Requer Node 18+ e o Claude Code instalado.

Métricas

Estrelas
18
Forks
1
Acompanhando
2
Saúde
42%
Último commit
há 1 semana
Versão
v3.2.0
Issues abertas
0
Contribuidores
2

Casos de uso

  • Educação em criptografia e história da computação
  • Pesquisa sobre sistemas criptográficos históricos
  • Decodificação de mensagens Enigma autênticas
  • Exploração de algoritmos de cifragem clássica

Veredito

Implementação rigorosa e reconhecida mundialmente de simulador Enigma. Ideal para fins educacionais e pesquisa histórica em criptografia, com código bem estruturado e extensível para experimentação técnica.

README

A tradução para o português deste README ainda está na fila.

Enigma Python library

About

Welcome to enigmapython, a Python package designed to emulate the legendary Enigma cryptographic machine used during World War II. enigmapython provides a faithful implementation of the Enigma machine, allowing users to explore and understand the workings of this historic device.

This project is listed on Wikipedia as a globally recognized Enigma machine simulator, noted for its historical accuracy.

Key Features

  • Flexible Configuration: enigmapython allows customization of the Enigma machine configuration, enabling users to experiment with different rotor settings, reflectors, and ring positions.
  • Easy Extension: enigmapython is designed to be easily extensible, allowing developers to add new features or enhance the existing implementation.
  • Simple yet faithful: don't be fooled by its simplicity; enigmapython implements 100% the algorithms of many Enigma machine models, allowing to decode a message that has been encoded by a real Enigma machine and also the contrary.

Enigma mechanics

For a detailed description of the rotor movement and stepping logic, including pseudocode, please refer to the Enigma Mechanics documentation.

Historical Accuracy & Verification

enigmapython is rigorously tested against authentic historical data to ensure maximum accuracy.

Machines implementations

The following Enigma machine models (along with their rotors, reflectors and plugboards) have been implemented:

Enigma B (Sweden, s/n: A-133)*

ScramblerWiringTurnoverImplemented
ETW (passthrough)abcdefghijklmnopqrstuvxyzåäöN/A✅
Rotor Ipsbgöxqjdhoäucfrtezvåinlymkaä✅
Rotor IIchnsyöadmotrzxbäigåekqupflvjä✅
Rotor IIIåvqiaäxrjbözspcfyunthdomekglä✅
Reflector UKWldgbäncpskjavfzhxuiårmqöoteyN/A✅

*given the rarity of this model and the little documentation/simulators available, although I expect an encryption consistency on par with newer models, I was unable to test it as I would have liked

Enigma K (Commercial Enigma)

ScramblerWiringTurnoverImplemented
ETW "QWERTZ"qwertzuioasdfghjkpyxcvbnmlN/A✅
Rotor Ilpgszmhaeoqkvxrfybutnicjdwy✅
Rotor IIslvgbtfxjqohewirzyamkpcndue✅
Rotor IIIcjgdpshkturawzxfmynqobvlien✅
Reflector UKWimetcgfraysqbzxwlhkdvupojnN/A✅

Enigma K Swiss

ScramblerWiringTurnoverImplemented
ETW "QWERTZ"qwertzuioasdfghjkpyxcvbnmlN/A✅
Rotor Ipezuohxscvfmtbglrinqjwaydky✅
Rotor IIzouesydkfwpciqxhmvblgnjrate✅
Rotor IIIehrvxgaobqusimzflynwktpdjcn✅
Reflector UKWimetcgfraysqbzxwlhkdvupojnN/A✅

Enigma D (Commercial Enigma)

ScramblerWiringTurnoverImplemented
ETW "QWERTZ"qwertzuioasdfghjkpyxcvbnmlN/A✅
Rotor Ilpgszmhaeoqkvxrfybutnicjdwz*✅
Rotor IIslvgbtfxjqohewirzyamkpcnduz*✅
Rotor IIIcjgdpshkturawzxfmynqobvliez*✅
Reflector UKWimetcgfraysqbzxwlhkdvupojnN/A✅

*Enigma D rotor turnover happens at Z when ringstellung is 0 (A), otherwise turnover position is calculated using the formula turnover = (ringstellung + 1) % 26.

Enigma Z (Z30 Mark I)*

Compared to the other machine models, this one encrypts numbers instead of letters.

ScramblerWiringTurnoverImplemented
ETW (passthrough)1234567890N/A✅
Rotor I64182703599✅
Rotor II58410976329✅
Rotor III35816207949✅
Reflector UKW5079183642N/A✅

*given the rarity of this model and the little documentation/simulators available, although I expect an encryption consistency on par with newer models, I was unable to test it as I would have liked

Enigma I

ScramblerWiringTurnoverImplemented
Plugboard (passthrough+swappable)N/AN/A✅
ETW (passthrough)abcdefghijklmnopqrstuvwxyzN/A✅
Rotor Iekmflgdqvzntowyhxuspaibrcjq✅
Rotor IIajdksiruxblhwtmcqgznpyfvoee✅
Rotor IIIbdfhjlcprtxvznyeiwgakmusqov✅
Reflector AejmzalyxvbwfcrquontspikhgdN/A✅
Reflector ByruhqsldpxngokmiebfzcwvjatN/A✅
Reflector CfvpjiaoyedrzxwgctkuqsbnmhlN/A✅

Enigma I Norway (Norenigma)

ScramblerWiringTurnoverImplemented
Plugboard (passthrough+swappable)N/AN/A✅
ETW (passthrough)abcdefghijklmnopqrstuvwxyzN/A✅
Rotor Iwtokasuyvrbxjhqcpzefmdinlgq✅
Rotor IIgjlpubswemctqvhxaofzdrkynie✅
Rotor IIIjwfmhnbpusdytixvzgrqlaoekcv✅
Rotor IVfgzjmvxepbwshqtliudykcnraoj✅
Rotor Vhejxqotzbvfdascilwpgynmurkz✅
Reflector UKWmowjypuxndsraibfvlkzgqchetN/A✅

Enigma I Sondermaschine (special machine)

ScramblerWiringTurnoverImplemented
Plugboard (passthrough+swappable)N/AN/A✅
ETW (passthrough)abcdefghijklmnopqrstuvwxyzN/A✅
Rotor Iveosirzujdqckgwypnxaflthmbq✅
Rotor IIuemoatqlshpkcyfwjzbgvxidnre✅
Rotor IIItzhxmbsipnurjfdkeqvcwglaoyv✅
Reflector UKWciagsndrbytpzfulvhekoqxwjmN/A✅

Enigma M3

ScramblerWiringTurnoverImplemented
Plugboard (passthrough+swappable)N/AN/A✅
ETW (passthrough)abcdefghijklmnopqrstuvwxyzN/A✅
Rotor Iekmflgdqvzntowyhxuspaibrcjq✅
Rotor IIajdksiruxblhwtmcqgznpyfvoee✅
Rotor IIIbdfhjlcprtxvznyeiwgakmusqov✅
Rotor IVesovpzjayquirhxlnftgkdcmwbj✅
Rotor Vvzbrgityupsdnhlxawmjqofeckz✅
Rotor VIjpgvoumfyqbenhzrdkasxlictwm, z✅
Rotor VIInzjhgrcxmyswboufaivlpekqdtm, z✅
Rotor VIIIfkqhtlxocbjspdzramewniuygvm, z✅
Reflector ByruhqsldpxngokmiebfzcwvjatN/A✅
Reflector CfvpjiaoyedrzxwgctkuqsbnmhlN/A✅

Enigma M4

ScramblerWiringTurnoverImplemented
Plugboard (passthrough+swappable)N/AN/A✅
ETW (passthrough)abcdefghijklmnopqrstuvwxyzN/A✅
Rotor Iekmflgdqvzntowyhxuspaibrcjq✅
Rotor IIajdksiruxblhwtmcqgznpyfvoee✅
Rotor IIIbdfhjlcprtxvznyeiwgakmusqov✅
Rotor IVesovpzjayquirhxlnftgkdcmwbj✅
Rotor Vvzbrgityupsdnhlxawmjqofeckz✅
Rotor VIjpgvoumfyqbenhzrdkasxlictwm, z✅
Rotor VIInzjhgrcxmyswboufaivlpekqdtm, z✅
Rotor VIIIfkqhtlxocbjspdzramewniuygvm, z✅
BetaleyjvcnixwpbqmdrtakzgfuhosN/A✅
GammafsokanuerhmbtiycwlqpzxvgjdN/A✅
Reflector B ThinenkqauywjicopblmdxzvfthrgsN/A✅
Reflector C ThinrdobjntkvehmlfcwzaxgyipsuqN/A✅

Custom Machine

ScramblerWiringTurnoverImplemented
Plugboard (passthrough+swappable)N/AN/A✅
ETW (Entry Wheel)CustomN/A✅
RotorCustomCustom✅
ReflectorCustomN/A✅

You can create a fully customized Enigma machine by instantiating the base components manually. This allows you to define custom alphabets, wirings, and turnover positions.

from enigmapython.Enigma import Enigma
from enigmapython.Rotor import Rotor
from enigmapython.Reflector import Reflector
from enigmapython.SwappablePlugboard import SwappablePlugboard
from enigmapython.Etw import Etw
from enigmapython.Alphabets import Alphabets

# 1. Define alphabet
alphabet = Alphabets.lookup.get("latin_i18n_26chars_lowercase")

# 2. Create custom rotors
# Parameters: wiring, turnover_indexes, alphabet, initial_position, ring_setting
rotor1 = Rotor("ekmflgdqvzntowyhxuspaibrcj", [16], alphabet, 0, 0) # Turnover at 'q'
rotor2 = Rotor("ajdksiruxblhwtmcqgznpyfvoe", [4], alphabet, 0, 0)  # Turnover at 'e'
rotor3 = Rotor("bdfhjlcprtxvznyeiwgakmusqo", [21], alphabet, 0, 0) # Turnover at 'v'

# 3. Create custom reflector
reflector = Reflector("yruhqsldpxngokmiebfzcwvjat", alphabet)

# 4. Create other components
# Swappable plugboard allows you to connect pairs of letters
plugboard = SwappablePlugboard(alphabet=alphabet)
plugboard.swap("a", "z") # Example: swap 'a' with 'z'

etw = Etw(alphabet, alphabet) # Passthrough ETW using alphabet as wiring

# 5. Assemble the Enigma machine
engine = Enigma(plugboard, [rotor1, rotor2, rotor3], reflector, etw, auto_increment_rotors=True, alphabet=alphabet)

# 6. Encrypt/Decrypt
cipher = engine.input_string("hello")
print(f"Ciphertext: {cipher}") # Outputs: mfnca

Prerequisites

  • Python 3.11
  • Clone this repo, checkout the desired branch/tag and install requirements (pip install -r requirements.txt) or directly from PyPI using pip install enigmapython

Getting started

Get started by installing the package from PyPI (pip install enigmapython) and exploring the examples in the examples folder.

Documentation

Full API documentation is available on ReadTheDocs.

For additional details, you can also refer to the local documentation, examples, and code comments.

Known implementations

Here's a list containing all the known Enigma simulators that use the enigmapython API.

  • Enigma TUI. Enigma TUI is a Terminal User Interface for Enigma machines, allowing you to simulate different Enigma machine models from the terminal. It employs enigmapython as Enigma engine.

In the case you leveraged enigmapython API in a project, either public or not, drop me an email at denis.maggiorotto[at]gmail.com and I'll be happy to list you here.

Credits/references

Support

Found it useful/funny/educational? Please consider to Buy Me a Coffee or Star this repo

Ver o original no GitHub

Bom para

Relacionados