Giter Site home page Giter Site logo

enigma_cipher_machine's Introduction

The enigma crate implements an Enigma machine cipher along with the components (i.e., rotors and reflectors) for the Wehrmacht and Luftwaffe versions.

Usage

CLI

The enigma binary takes text (encoded or otherwise) and an Enigma machine configuration string as input, runs the text through the configured machine, and outputs the result.

enigma -i "hello, how are you doing" -c "A;III-A-A,II-A-A,I-A-A;a-b"
LZFAD, AMT GPJ FND IFMJY

Encryption and decyption is handled in the same was due to the nature of Enigma.

enigma -i "LZFAD, AMT GPJ FND IFMJY" -c "A;III-A-A,II-A-A,I-A-A;a-b"
HELLO, HOW ARE YOU DOING

Configuration

The enigma configuration string specifies all details for the machine.

"A;III-A-A,II-A-A,I-A-A;a-b"

This configuration is laid out as through you're looking at an Enigma machine from the front and represents the reflect, rotor, and plugboard configurations.

The configuration string is broken up into three components.

<Reflector Id>;<Rotor Configurations>;<Plugboard mappings>

The Reflector Id is one of the Wehrmacht and Luftwaffe reflectors. See the Reflector page for valid options.

A rotor configuration specifies a rotor id and the position and ring location settings. See the rotor module page for valid rotor ids.

III-A-A
<Rotor Id>-<Position>-<Ring Location>

The plugboard mappings specify the character ports that a plug is connecting. For example, the following connects A and B and C to D on the plugboard. Note that the order doesn't matter.

<Reflector Id>;<Rotor Configuration>;a-b,d-c

API

EnigmaMachine and EnigmaMachineBuilder can be used to build and run an Enigma programmatically.

use enigma::machine::EnigmaMachine;

let builder = EnigmaMachine::builder();
let mut machine = builder
    .reflector("A")
    .plugboard(vec![('A', 'B')])
    .rotors(vec![
        ("I".to_string(), 0, 0),
        ("III".to_string(), 0, 0),
        ("II".to_string(), 0, 0),
    ])
    .build().unwrap();

let trans = machine.translate_text("Hello, how are you".chars());

Future Improvements

Only a portion of the available rotors and reflectors are currently implemented. Specifically, the Beta and Gamma rotors and the thin Kriegsmarine M4 reflectors are not implemented. The implementation of the machine will handle all of these without issue, including the fourth rotor of the Kriegsmarine M4.

Some cryptanalysis tooling would be fun to implement. See the Practical Cryptography and Computerphile links for some motivation.

Additional Details

There are a lot of amazing resources for studying the internal workings of the Enigma and the incredible work undertaken to break the code. The following contained useful technical details or inspiration when implementing this.

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.