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

Copyright(c) Colin Woodbury 2015 - 2020
LicenseBSD3
MaintainerColin Woodbury <colin@fosskers.ca>
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.

Instance details

Defined in Crypto.Classical.Cipher.Enigma

Cipher [ / 26] Stream Source # 
Instance details

Defined in Crypto.Classical.Cipher.Stream

Cipher [ / 26] Vigenère Source # 
Instance details

Defined in Crypto.Classical.Cipher.Vigenere

Cipher ( / 26, / 26) Affine Source # 
Instance details

Defined in Crypto.Classical.Cipher.Affine

Cipher (Map Char Char) Substitution Source # 
Instance details

Defined in Crypto.Classical.Cipher.Substitution

Cipher ( / 26) Caesar Source # 
Instance details

Defined in Crypto.Classical.Cipher.Caesar

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.

Instance details

Defined in Crypto.Classical.Types

Methods

key :: CPRG g => g -> EnigmaKey Source #

Key [ / 26] Source #

Key for Stream/Vigenère Cipher.

Instance details

Defined in Crypto.Classical.Types

Methods

key :: CPRG g => g -> [ / 26] Source #

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.

Instance details

Defined in Crypto.Classical.Types

Methods

key :: CPRG g => g -> ( / 26, / 26) Source #

Key (Map Char Char) Source #

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

Instance details

Defined in Crypto.Classical.Types

Methods

key :: CPRG g => g -> Map Char Char Source #

Key ( / 26) Source # 
Instance details

Defined in Crypto.Classical.Types

Methods

key :: CPRG g => g -> / 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).

Instances
Eq EnigmaKey Source # 
Instance details

Defined in Crypto.Classical.Types

Show EnigmaKey Source # 
Instance details

Defined in Crypto.Classical.Types

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.

Instance details

Defined in Crypto.Classical.Types

Methods

key :: CPRG g => g -> EnigmaKey Source #

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.

Instance details

Defined in Crypto.Classical.Cipher.Enigma

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

Instances
Eq Rotor Source # 
Instance details

Defined in Crypto.Classical.Types

Methods

(==) :: Rotor -> Rotor -> Bool #

(/=) :: Rotor -> Rotor -> Bool #

Show Rotor Source # 
Instance details

Defined in Crypto.Classical.Types

Methods

showsPrec :: Int -> Rotor -> ShowS #

show :: Rotor -> String #

showList :: [Rotor] -> ShowS #

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.

plugFrom :: [(Char, Char)] -> Plugboard Source #

Given a list of letter pairs, generates a Plugboard. Any letters left out of the pair list will be mapped to themselves.