Skip to content

henryhale/enigma

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

enigma

The World War II's cryptic game-changer, a mechanical marvel of secrecy and encryption

Overview

This repository features a TypeScript simulation of the iconic Enigma machine β€” an encryption device used by the German military during World War II.

Having watched The Imitation Game movie with prior understanding of cryptography, I decided to challenge myself into creating a simulation of the basic functionality of the original Enigma machines. Then later try to break it just like Alan Turing and his collegues did.

Now the first step is done πŸŽ‰

The rest of this document tells what I found out and provides a guide to run the simulation on your computer.

Live Demo

To try the live demo, first check out how to use it here.

Check out the simulation in action: Try it Yourself

How it Works

The Enigma machine consisted of rotors, reflector, plugboard and a keyboard. Each key press initiated a complex encryption process involving the rotation of rotors and the reflection of signals. Its daily-changing settings posed a significant challenge to Allied codebreakers.

The process of transforming an input character involves a sequence of steps through various components, including the plugboard, rotors, reflector, and plugboard again before reaching the lampboard. Here's a brief description of the transformation pipeline:

  1. Plugboard:

    • The input character enters the plugboard, where initial letter swaps occur. Pairs of letters are connected, providing an additional layer of complexity to the encryption.
  2. Rotors:

    • The character then passes through a series of rotors, each with its own internal wiring. As the rotors rotate with each keypress, the electrical signal is further scrambled through these intricate pathways.
  3. Reflector:

    • After passing through the rotors, the signal is directed to the reflector. The reflector ensures that the signal is then sent back through the rotors in a different path, contributing to the complexity of the encryption.
  4. Rotors (again):

    • The signal, now reflected, passes through the rotors again in the reverse direction. This double-pass through the rotors adds a crucial non-linearity to the encryption process.
  5. Plugboard (again):

    • The signal re-enters the plugboard for a second letter swap. This final permutation provides an additional layer of complexity to the output.
  6. Lampboard:

    • The transformed signal finally reaches the lampboard, where the illuminated letter represents the encrypted output. This letter corresponds to the final encrypted character.

The transformation process involves a carefully orchestrated series of steps through various components, creating a highly secure and dynamic encryption process during each keypress.

Getting Started

Follow these steps to set up and run the Enigma machine simulation on your local machine:

Prerequisites

  • Node.js installed on your machine

Installation

  1. Clone the repository:

    git clone https://github.com/henryhale/enigma.git
  2. Navigate to the project directory:

    cd enigma
  3. Install dependencies:

    npm install
    # pnpm install

Usage

Run the provided example script to witness the Enigma machine in action:

  • Node.js

    npm run simulate
    # pnpm simulate
  • Browser

    npm run dev
    # pnpm dev

Explore the script to create your own scenarios and delve into different Enigma machine configurations.

To build the simulation for production, run the provided command

npm run build
# pnpm build

Structure

Guide

This section focuses on the browser demo taking you through how to encrypt and decrypt messages

  • Open the demo locally in your browser or check out the live demo.
  • Mode: Encryption - select the encrypt radio button.
  • Rotors: For simplicity, leave each rotor position at 0 - A. Otherwise set the rotors to the desired positions say 0 - A, 1 - B, 2 - C. Be sure to note the order as it will be used to decrypt the messages.
  • Lampboard: Everytime you input a key, the output (ciphered) key will light up.
  • Input: Type the plain text message here.
  • Output: The output is represented the ciphered text from the input message.
  • Mode: Decryption - to decrypt the message, open the demo in another tab and select decrypt under the Mode section.
  • Rotors: Set the rotor positions to the values they were at during encryption.
  • Input: Enter the ciphered text into the input textarea.
  • Output: The corresponding result is the plaintext you entered during the encryption.

If you have reached this point, you have got it πŸŽ‰

Contributing

Contributions are welcome! If you have suggestions or improvements, feel free to open an issue or create a pull request.

References

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Copyright Β© 2023 Henry Hale