Last active
August 29, 2015 14:12
-
-
Save isaacabraham/38ca0794e03bf7ba9316 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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