Coder Social home page Coder Social logo

enigma's Introduction

Enigma cipher machine emulator

This is a neat little emulator of various Enigma machines with a lot of confugurable parameters. Somebody hurt your feelings by saying "my grandmother encrypts better than you"? I've got you covered! With this port of the amazing 1940's technology you'll be just as good at encrypting things as anyone's grandmother.

Usage

This repository contains both the CLI tool and its underlying library written in Go. The library is documented on GoDoc.

As for the CLI tool, a simple go get should do it:

go get github.com/emedvedev/enigma/cmd/enigma

While the full CLI syntax is a bit verbose, it's actually possible to use the tool without any source code modifications, config files, or Enigma knowledge:

enigma Never gonna give you up, never gonna let you down!

Using an Enigma machine with default settings is somewhat similar to setting your password to 0000. Let's up our security game:

enigma youtu.be/dQw4w9WgXcQ --rotors Beta VI I III --reflector C-Thin --plugboard AD SF ET RY HK JL QZ WX UM OP --rings 10 5 16 10

Much better! And of course, enigma -h will give you the complete description of parameters and usage.

Importantly, since Enigma machines only have 26 keys, spaces are replaced with X, and everything outside of the English alphabet is discarded. It's up to you to come up with a suitable encoding.

Enjoy!

Enigma models and features

Almost everything from the German Enigma machines can be configured in this emulator:

  • Rotor set: rotors from M3 and M4, the most famous Enigma machines, are pre-loaded.

  • Reflector: reflectors A, B, C (as well as thin B and C versions for M4) are supported.

  • Plugboard: any number of letter pairs is accepted. Plugboard configuration is optional.

  • Ring offsets and starting position of the rotors.

M3 and M4 can be fully emulated with the right parameters, and if it's not enough, new rotors and reflectors can be added quite easily: just add a new entry to the list in rotors.go, and that's it. Notches for rotor turnover are optional.

Some exotic Enigma variants and implementations, as well as devices such as Uhr, are not supported due to my chronic lack of spare time. Your pull requests would be most welcome!

Further reading

A bunch of material on Enigma machines, in no particular order. Explanations, specs, other emulators.

enigma's People

Contributors

emedvedev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

enigma's Issues

Enigma machines that were serialized using gob don't work

I need to persist an Enigma machine to bytes and restore it later. I use this function to save it

func saveEnigmaToFile(machine *enigma.Enigma, filename string) {
    buf := &bytes.Buffer{}
    enc := gob.NewEncoder(buf)

    enc.Encode(machine)

    file, err := os.Create(filename)
    defer file.Close()
    if err != nil {
        log.Fatal(err)
    }

    file.Write(buf.Bytes())
}

And restore it like this:

    var machine2 *enigma.Enigma
    machine2, err := loadEnigmaFromFile("machine99.bin")

But the restored machine's configuration is different from what was saved. Using degob, I see that it was serialized ok (added linefeeds for clarity).

{"Reflector":{"ID":"B",
"Sequence":[24,17,20,7,16,18,11,3,15,23,13,6,14,10,12,8,4,1,5,25,2,22,21,9,0,19]},
"Plugboard":[1,0,3,2,5,4,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25],
"Rotors":[
{"ID":"III",
"StraightSeq":[1,3,5,7,9,11,2,15,17,19,23,21,25,13,24,4,8,22,6,0,10,12,20,18,16,14],
"ReverseSeq":[19,0,6,1,15,2,18,3,16,4,20,5,21,13,25,7,24,8,23,9,22,11,17,10,14,12],
"Turnover":[21],"Offset":0,"Ring":0},
{"ID":"II",
"StraightSeq":[0,9,3,10,18,8,17,20,23,1,11,7,22,19,12,2,16,6,25,13,15,24,5,21,14,4],
"ReverseSeq":[0,9,15,2,25,22,17,11,5,1,3,10,14,19,24,20,16,6,4,13,7,23,12,8,21,18],
"Turnover":[4],"Offset":1,"Ring":0},
{"ID":"IV",
"StraightSeq":[4,18,14,21,15,25,9,0,24,16,20,8,17,7,23,11,13,5,19,6,10,3,2,12,22,1],
"ReverseSeq":[7,25,22,21,0,17,19,13,11,6,20,15,23,16,2,4,9,12,1,18,10,3,24,14,8,5],
"Turnover":[9],"Offset":2,"Ring":0}]}

But the Offset and Ring values are alwasy wrong for the second and thrid rotor, regardless of if the machine encrypted something or not.

Is there something special about the Enigma struct when it comes to serializing and deserializing it?

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.