Giter VIP home page Giter VIP logo

enigma's Introduction

Enigma

Build Status

Note: This algorithm has been shown to be utter garbage as-is, please do not use it for anything.

This library provides a symmetric key encryption algorithm inspired by the famous Enigma Machine used by Nazi Germany in World War 2. The original machine had two main hardware deficiencies that allowed the Allies to eventually crack it:

  1. To keep the machine small, it only had 3 (or 4, depending on the model) mechanical Rotors which each mapped an input value to some output. Wired together, these Rotors would map input letters pressed on a keyboard to output letters. With each input the Rotors would advance, changing the mapping. However, with so few Rotors, the amount of obfuscation steps that it could perform were limited.

  2. To address the above problem, the designers of the Enigma decided to have the output of the last Rotor feed back into itself, winding its way back through the machine. This artificially extends the Rotor count, but also proved to be the critical flaw.

More detailed explanations of the original machine can be easily found on the internet.

This library takes the following approach:

  1. It works on bits, not characters.
  2. The 26-letter Rotors are reduced to 2 possible bit transformations, "id" and "flip".
  3. We represent a single rotor as a single bit. 0 is "id", 1 is "flip".
  4. The entire machine (group of rotors) is represented by a series of bits.
  5. Like the original Enigma, our secret key is the initial state of the rotors, which is just a series of bits. It can thus be arbitrarily long to offer many many obfuscation steps.
  6. Like the original Enigma, each input (bit) is encrypted with a different key (rotor set).
  7. Like the original Enigma, the ciphering algorithm both encrypts and decrypts.
  8. The ciphering algorithm doesn't feed back into itself.

Examples

Encrypt a Word64:

λ evalState (cipher 1) $ Key 1
6513794518609451620

Decrypt a Word64:

λ evalState (cipher 6513794518609451620) $ Key 1
1

Chain encryptions, carrying over the rotor state between operations:

λ evalState ((,) <$> cipher 1 <*> cipher 2) $ Key 1
(6513794518609451620,7321263536672712088)

Encrypt a Foldable:

λ evalState (traverse cipher [1,2,3]) $ Key 1
[6513794518609451620,7321263536672712088,11932949555100099993]

Encrypt a message:

λ evalState (traverse (cipher . fromIntegral . ord) "Hint") $ Key 1
[6513794518609451565,7321263536672712179,11932949555100100084,6513794518609451537]

Performance

(More benchmarks needed)

Machine: ThinkPad X1 Carbon w/ Intel COREi7

Encrypting... Average Time
Single Word64 1.9 μs
10k Word64 19.5 ms
1mil Word64 (~7.5mb) 1.95 s

enigma's People

Contributors

fosskers avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  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.