Code Monkey home page Code Monkey logo

argentini / argentini.enigma Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 0.0 40 KB

A virtual Enigma Machine that enciphers and deciphers UTF-16 strings, and which can be used for keyless encryption in mobile, desktop, and server apps (Windows, macOS, Linux, .NET 8.0, x64, Arm64, Apple Silicon).

Home Page: https://nonsequiturs.com/

License: MIT License

C# 100.00%
crypto cryptography enigma machine cipher dotnet encryption enigma-machine keyless keyless-cipher

argentini.enigma's Introduction

What is the Enigma Machine?

The Enigma machine is a cipher device developed and used in the early- to mid-20th century to protect commercial, diplomatic, and military communication. It was employed extensively by Nazi Germany during World War II, in all branches of the German military. The Enigma machine was considered so secure that it was used to encipher the most top-secret messages.

Learn more about it at https://en.wikipedia.org/wiki/Enigma_machine.

The Project

This project is a virtual Enigma Machine that supports the entire UTF-16 character set, whereas the original German hardware only supported 26 uppercase letters (no spaces!).

Just like the physical device, machine state is used to both encipher and decipher text with the same functions (like a text toggle). This virtual version works with UTF-16 strings using a keyless algorythm based on the inner workings of the original hardware. To accomplish this, it uses a custom predictable random number generator (PRNG) to ensure the cipher will work on any supported platform.

Unlike the original hardware, you can add as many virtual rotors as you like, set the cipher seeds for all machine components (effectively randomizing the character sets they use), set starting rotor positions, and more, which will improve the overall cipher strength. Because the entire UTF-16 character set is used, the cipher strength is already exponentially better even without additional rotors, and should meet modern keyless cryptography needs.

It's easy to create a new EnigmaMachine object and encipher/decipher your own text:

var enigmaMachine = new EnigmaMachine(new EnigmaConfiguration
{
    PlugBoardCipherSeed = 1234567,
    ReflectorCipherSeed = 6789101,
    Rotors = new List<EnigmaRotor> // Rotors work top to bottom; original hardware has them right to left
    {
        new (rotorCipherSeed: 9876543210, rotorStartingPosition: 0, advanceNextRotorIncrement: 50),
        new (rotorCipherSeed: 1234567890, rotorStartingPosition: 0, advanceNextRotorIncrement: 25),
        new (rotorCipherSeed: 1029384756, rotorStartingPosition: 0) // No neighbor for the last rotor to advance
    }
});

var message = @"
Fynydd is a software development & hosting company.
Fynydd is a Welsh word (prounounced: /ˈvənɨ̞ð/) that means mountain or hill.
";

var enciphered = enigma.RunCipher(message);
var deciphered = enigma.RunCipher(enciphered);

Assert.Equal(message, deciphered);

This project is a .NET library with xUnit tests, so you can easily play with the virtual Enigma Machine.

argentini.enigma's People

Contributors

argentini avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.