crypto-classical-0.0.3: An educational tool for studying classical cryptography schemes.

Copyright(c) Colin Woodbury, 2015
LicenseBSD3
MaintainerColin Woodbury <colingw@gmail.com>
Safe HaskellNone
LanguageHaskell2010

Crypto.Classical.Cipher.Enigma

Description

 

Synopsis

Documentation

newtype Enigma a Source

Constructors

Enigma 

Fields

_enigma :: a
 

Instances

Monad Enigma 
Functor Enigma 
Applicative Enigma 
Cipher EnigmaKey Enigma

When a machine operator presses a key, the Rotors rotate. A circuit is then completed as they hold the key down, and a bulb is lit. Here, we make sure to rotate the Rotors before encrypting the character. NOTE: Decryption is the same as encryption.

Eq a => Eq (Enigma a) 
Show a => Show (Enigma a) 

enigma :: forall a a. Iso (Enigma a) (Enigma a) a a Source

withInitPositions :: EnigmaKey -> EnigmaKey Source

Applies the initial Rotor settings as defined in the Key to the Rotors themselves. These initial rotations do not trigger the turnover of neighbouring Rotors as usual.

turn :: [Rotor] -> [Rotor] Source

Turn the (machine's) right-most (left-most in List) Rotor by one position. If its turnover value wraps back to 25, then turn the next Rotor as well.

rotate :: ( / 26) -> Map ( / 26) ( / 26) -> Map ( / 26) ( / 26) Source

Rotate a Rotor by n positions. By subtracting 1 from every key and value, we perfectly simulate rotation. Example:

>>> rotate $ M.fromList [(0,2),(1,0),(2,3),(3,4),(4,1)]
M.fromList [(4,1),(0,4),(1,2),(2,3),(3,0)]