{ uuX      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI J K L M N O P Q R S T U V W (c) Colin Woodbury, 2015BSD3"Colin Woodbury <colingw@gmail.com>None(JK(Must be passed a number coprime with 26.|The sequence (r1,...r[n-1]) of numbers such that r[i] is an independent sample from a uniform random distribution [0..n-i]~Invert a Map. Keys become values, values become keys. Note that this operation may result in a smaller Map than the original.Compose two Maps. If some key v( isn't present in the second Map, then k will be left out of the result.Q2015 April 16 @ 13:56 Would it be possible to make a Category for Map like this?*An alias for compose. Works left-to-right.HZip a list on itself. Takes pairs of values and forms a tuple. Example:uniZip [1,2,3,4,5,6][(1,2),(3,4),(5,6)]    (c) Colin Woodbury, 2015BSD3"Colin Woodbury <colingw@gmail.com>None Given a sequence (e1,...en) to shuffle, its length, and a random generator, compute the corresponding permutation of the input sequence.XGiven a sequence (e1,...en) to shuffle, and a sequence (r1,...r[n-1]) of numbers such that r[i] is an independent sample from a uniform random distribution [0..n-i], compute the corresponding permutation of the input sequence.YZ[\ X  Y[Z\ X(c) Colin Woodbury, 2015BSD3"Colin Woodbury <colingw@gmail.com>None (2468JK 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.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  and  algorithms.Randomly generate a Key.WA Cipher must be able to encrypt and decrypt. The Cipher type determines the Key type.]Key for Stream/Vigenre Cipher.^;Key for Substitution Cipher. The Key is the Mapping itself._For Affine Ciphers. aM must be coprime with 26, or else a^-1 won't exist and and we can't decrypt.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).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.LA 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.`Rotor I: Turnover from Q to R.aRotor II: Turnover from E to F.b Rotor III: Turnover from V to W.cRotor IV: Turnover from J to K.dRotor V: Turnover from Z to A.e/Generate random start positions for the Rotors.fGenerate settings for the Plugboard. Ten pairs of characters will be mapped to each other, and the remaining six characters will map to themselves.gNote 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.& ]^_h`abcdi !"efg  !" !"   ]^_h`abcdi !"efg(c) Colin Woodbury, 2015BSD3"Colin Woodbury <colingw@gmail.com>None (-246JK#MAn Affine Cipher is a non-random Substitution Cipher, such that a character x; is mapped to a cipher character according to the equation:f(x) = ax + b (mod 26)Also known as a Linear Cipher.#$%&'()#$%&#$%&)('#$%&'()(c) Colin Woodbury, 2015BSD3"Colin Woodbury <colingw@gmail.com>None(-246JK*cA simple Shift Cipher. The key is a number by which to shift each letter in the alphabet. Example:0encrypt 3 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ^. caesar"DEFGHIJKLMNOPQRSTUVWXYZABC"*+,-./0*+,-*+,-0/.*+,-./0(c) Colin Woodbury, 2015BSD3"Colin Woodbury <colingw@gmail.com>None(-6JK5Applies 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.6Turn 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.7Rotate a Rotor by n` positions. By subtracting 1 from every key and value, we perfectly simulate rotation. Example:3rotate $ M.fromList [(0,2),(1,0),(2,3),(3,4),(4,1)]*M.fromList [(4,1),(0,4),(1,2),(2,3),(3,0)]8When 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. 123456789:1234567 1234:98567123456789:(c) Colin Woodbury, 2015BSD3"Colin Woodbury <colingw@gmail.com>None(-246JK;A Cipher with pseudorandom keys as long as the plaintext. Since Haskell is lazy, our keys here are actually of infinite length.:If for whatever reason a key of finite length is given to =, the ciphertext is cutoff to match the key length. Example:"encrypt [1,2,3] "ABCDEF" ^. stream"BDF";<=>?@A;<=>;<=>A@?;<=>?@A(c) Colin Woodbury, 2015BSD3"Colin Woodbury <colingw@gmail.com>None-246BqA Cipher whose key is a (pseudo)random mapping of characters to other characters. A character may map to itself.BCDEFGHBCDEBCDEHGFBCDEFGH (c) Colin Woodbury, 2015BSD3"Colin Woodbury <colingw@gmail.com>None(-246JKIA Vigenre Cipher is just a Stream Cipher with a finite key, shorter than the length of the plaintext. The key is repeated for the entire length of the plaintext.MkDetermine a Vigenre key from a Stream key. Weakness here: key length is a factor of the plaintext length.IJKLMNOPIJKLMIJKLPONMIJKLMNOP (c) Colin Woodbury, 2015BSD3"Colin Woodbury <colingw@gmail.com> Safe-InferredQA Q is a capital Ascii letter (A-Z)QRSTQRSQRSTQRST (c) Colin Woodbury, 2015BSD3"Colin Woodbury <colingw@gmail.com>None#$%&*+,-1234567;<=>BCDEIJKLM (c) Colin Woodbury, 2015BSD3"Colin Woodbury <colingw@gmail.com>NoneEURun every test on every Cipher.V>An encrypted message should decrypt to the original plaintext.W)A message should never encrypt to itself.j2Different keys should yield different encryptions.k%A letter can never encrypt to itself.lEncrypt and unwrap a message.mA small manual test of Enigma.UVWjklmnUVWVWUUVWjklmn (c) Colin Woodbury, 2015BSD3"Colin Woodbury <colingw@gmail.com>NoneE  !"#$%&*+,-1234567;<=>BCDEIJKLMQRSUVWo !!"#$%&'()*+,-.//01234556789:;;<=>?@ABCDDEFGHIJJKLMNO P P Q R S T U V W W X Y Z [ \]^_`abcdefghijklmn o p q r stcrypto-classical-0.0.3Crypto.Classical.UtilCrypto.Classical.ShuffleCrypto.Classical.TypesCrypto.Classical.Cipher.AffineCrypto.Classical.Cipher.CaesarCrypto.Classical.Cipher.EnigmaCrypto.Classical.Cipher.Stream$Crypto.Classical.Cipher.Substitution Crypto.Classical.Cipher.VigenereCrypto.Classical.LetterCrypto.Classical.TestCrypto.Classical.CipherCrypto.Classicalletterintinverseprngrseq mapInversecompose|.|uniZipshuffleRotor_name _turnover_circuitKeykeyCipherencryptdecrypt EnigmaKey_rotors _settings _reflector _plugboard Plugboard Reflectorcircuitnameturnover plugboard reflectorrotorssettingsAffine_affineaffine$fCipher(,)Affine $fMonadAffine$fApplicativeAffineCaesar_caesarcaesar$fCipherModCaesar $fMonadCaesar$fApplicativeCaesarEnigma_enigmaenigmawithInitPositionsturnrotate$fCipherEnigmaKeyEnigma $fMonadEnigma$fApplicativeEnigmaStream_streamstream$fCipher[]Stream $fMonadStream$fApplicativeStream Substitution _substitution substitution$fCipherMapSubstitution$fMonadSubstitution$fApplicativeSubstitution Vigenère _vigenère vigenèrevigKey$fCipher[]Vigenère$fMonadVigenère$fApplicativeVigenèreLetter_char$fArbitraryLettertestAllcycleTnotSelfTshuffle'TreeNodeLeaf buildTree$fKey[]$fKeyMap$fKey(,)rIrIIrIIIrIVrV randCharsrandPlug$fKeyEnigmaKey$fKeyModukwBdiffKeyTnoSelfMappingTeenig$fArbitraryByteString