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

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

Crypto.Classical.Types

Contents

Description

 

Synopsis

Cipher

class Key k => Cipher k a | a -> k where Source

A Cipher must be able to encrypt and decrypt. The Cipher type determines the Key type.

Instances

Cipher EnigmaKey Enigma Source

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.

Cipher [(/) ℤ 26] Stream Source 
Cipher [(/) ℤ 26] Vigenère Source 
Cipher ((/) ℤ 26, (/) ℤ 26) Affine Source 
Cipher (Map Char Char) Substitution Source 
Cipher ((/) ℤ 26) Caesar Source 

Keys

class Key a where Source

Keys can appear in a number of different forms. E.g. a single number, a tuple, a mapping, etc. Each needs to be interpreted uniquely by a Cipher's encrypt and decrypt algorithms.

Methods

key :: CPRG g => g -> a Source

Randomly generate a Key.

Instances

Key EnigmaKey Source

Note that the randomly generated initial Rotor positions are not applied to the Rotors when the key is generated. They have to be applied before first use.

Key [(/) ℤ 26] Source

Key for Stream/Vigenère Cipher.

Key ((/) ℤ 26, (/) ℤ 26) Source

For Affine Ciphers. a must be coprime with 26, or else a^-1 won't exist and and we can't decrypt.

Key (Map Char Char) Source

Key for Substitution Cipher. The Key is the Mapping itself.

Key ((/) ℤ 26) Source 

Enigma Types

data EnigmaKey Source

Essentially the machine itself. It is made up of: 1. Three rotor choices from five, in a random placement. 2. Initial settings of those Rotors. 3. The Reflector model in use. 4. Plugboard settings (pairs of characters).

Constructors

EnigmaKey 

Instances

Eq EnigmaKey Source 
Show EnigmaKey Source 
Key EnigmaKey Source

Note that the randomly generated initial Rotor positions are not applied to the Rotors when the key is generated. They have to be applied before first use.

Cipher EnigmaKey Enigma Source

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.

data Rotor Source

A Rotor (German: Walze) is a wheel labelled A to Z, with internal wirings from each entry point to exit point. There is also a turnover point, upon which a Rotor would turn its left neighbour as well. Typically said turnover point is thought of in terms of letters (e.g. Q->R for Rotor I). Here, we represent the turnover point as a distance from A (or 0, the first entry point). As the Rotor rotates, this value decrements. When it rolls back to 25 (modular arithmetic), we rotate the next Rotor.

Our Rotors are letter-agnostic. That is, they only map numeric entry points to exit points. This allows us to simulate rotation very simply with Lenses.

Constructors

Rotor 

Fields

_name :: Text
 
_turnover :: ℤ / 26
 
_circuit :: Map (ℤ / 26) (ℤ / 26)
 

type Reflector = Map (ℤ / 26) (ℤ / 26) Source

A unmoving map, similar to the Rotors, which feeds the electrical current back into Rotors. This would never feed the left Rotor's letter back to itself, meaning a plaintext character would never encrypt to itself. This was a major weakness in scheme which allowed the Allies to make Known Plaintext Attacks against the machine.

type Plugboard = Map (ℤ / 26) (ℤ / 26) Source

A set of 10 pairs of connected letters which would map letters to other ones both before and after being put through the Rotors. The remaining six unpaired letters can be thought of mapping to themselves.

name :: Lens' Rotor Text Source

turnover :: Lens' Rotor ((/) ℤ 26) Source

circuit :: Lens' Rotor (Map ((/) ℤ 26) ((/) ℤ 26)) Source