Giter VIP home page Giter VIP logo

enigma's Introduction

Enigma Machine

The Enigma machine is an electro-mechanical encryption device used during World War II. It enciphers messages using a series of rotors and a reflector, which allowed for secure communication among the German military.

How it works:

Rotor class: Represents a single rotor in the Enigma machine. It takes a wiring parameter that defines the substitution wiring, a notch position for turnover, a ring_setting to configure the initial position of the ring, and an offset to set the initial position of the rotor.

Reflector class: Represents the reflector in the Enigma machine. It takes a wiring parameter that defines the substitution wiring for the reflector.

EnigmaMachine class: Represents the entire Enigma machine. It takes three parameters: rotor_settings, reflector_wiring, and plugboard_connections. rotor_settings is a list of tuples, each containing the wiring, notch, ring_setting, and offset for each rotor. reflector_wiring defines the substitution wiring for the reflector, and plugboard_connections is a list of plugboard pairs.

substitute_plugboard(char): This method substitutes characters based on the plugboard connections defined in plugboard_connections.

encrypt(message): This method takes a message as input and encrypts it using the Enigma machine. It performs the following steps:

  • Substitutes characters based on plugboard connections.
  • Passes the character through each rotor from left to right using the substitute_forward method.
  • Reflects the character using the reflector.
  • Passes the character through each rotor in reverse order using the substitute_backward method.
  • Substitutes characters based on plugboard connections again.
  • Rotates the first rotor, and if a notch is reached, rotates the next rotor.

Usage:

To use the Enigma machine, create an instance of the EnigmaMachine class with appropriate rotor settings, reflector wiring, and plugboard connections. Then, call the encrypt(message) method with the message you want to encrypt. The encrypted message will be returned.

Example usage:

rotor_settings = [
    ("EKMFLGDQVZNTOWYHXUSPAIBRCJ", "Q", 0, 0),
    ("AJDKSIRUXBLHWTMCQGZNPYFVOE", "E", 0, 0),
    ("BDFHJLCPRTXVZNYEIWGAKMUSQO", "V", 0, 0),
]
reflector_wiring = "YRUHQSLDPXNGOKMIEBFZCWVJAT"
plugboard_connections = [("A", "M"), ("G", "L"), ("P", "R"), ("S", "T")]

enigma = EnigmaMachine(rotor_settings, reflector_wiring, plugboard_connections)
message = "HELLO"
encrypted_message = enigma.encrypt(message)
print("Original message:", message)
print("Encrypted message:", encrypted_message) 

Note: This implementation is a simplified version of the historical Enigma machine, mainly for educational purposes, and may not include all the complexities and features of the original machine used during World War II.

enigma's People

Contributors

alonefps avatar

Stargazers

W.Sousa avatar Mateus Felipe Gonçalves avatar

Watchers

 avatar

Forkers

mateusfg7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.