Skip to content

Instantly share code, notes, and snippets.

@isaacabraham
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacabraham/38ca0794e03bf7ba9316 to your computer and use it in GitHub Desktop.
Save isaacabraham/38ca0794e03bf7ba9316 to your computer and use it in GitHub Desktop.
namespace Enigma
open System
type AlphabetMapping = string
type RingSetting = RingSetting of char
type WheelPosition = WheelPosition of char
type KnockOn = WheelPosition list
type PlugBoard = PlugBoard of string list
type Reflector = Reflector of AlphabetMapping
type Rotor =
{ Mapping : AlphabetMapping
KnockOns : KnockOn
RingSetting : RingSetting }
type Enigma =
{ Left : Rotor * WheelPosition
Middle : Rotor * WheelPosition
Right : Rotor * WheelPosition
Reflector : Reflector
Plugboard : PlugBoard }
// Example usage
let rotor1 =
{ Mapping = "EKMFLGDQVZNTOWYHXUSPAIBRCJ" // map these to ABCDEF...XYZ
KnockOns = [ WheelPosition 'E' ] // flip adjecent rotor whenever this one reaches "E"
RingSetting = RingSetting 'A' } // default ring setting
let reflectorA = Reflector "EJMZALYXVBWFCRQUONTSPIKHGD"
let myEnigma = { Left = rotor1, WheelPosition 'A'
Middle = rotor2, WheelPosition 'A'
Right = rotor3, WheelPosition 'A'
Reflector = reflectorA
Plugboard = Plugboard "AB VS DG CL HU FZ KN IM RW OX" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment