Fynydd Blog

Company and tech industry news, featured projects, open source code, tech tips, and more.
Post Categories

Open Source: Enigma Machine

Published on Monday, April 15, 2024

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.

An original Engima Machine, circa 1945 An original Engima Machine, circa 1945

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);
Screenshots

How can we help?

Whether your organization is big or small, book a conference call or request a project estimate and find out how Fynydd can help with your next web development or mobile app project!

Powered by Umbraco CMS with Sfumato™ and Tolnedra™

© 2024, Fynydd LLC

Privacy Policy

By using this website you accept our privacy policy. Choose the browser data you consent to allow:

Only Required
Accept and Close