crypto-classical 0.1.0 → 0.2.0
raw patch · 12 files changed
+49/−42 lines, 12 filesdep +microlensdep +microlens-thdep −lensPVP ok
version bump matches the API change (PVP)
Dependencies added: microlens, microlens-th
Dependencies removed: lens
API changes (from Hackage documentation)
- Crypto.Classical.Cipher.Affine: affine :: Iso (Affine a_afrg) (Affine a_afub) a_afrg a_afub
+ Crypto.Classical.Cipher.Affine: affine :: Lens (Affine a_adzJ) (Affine a_adCe) a_adzJ a_adCe
- Crypto.Classical.Cipher.Caesar: caesar :: Iso (Caesar a_afRT) (Caesar a_afUj) a_afRT a_afUj
+ Crypto.Classical.Cipher.Caesar: caesar :: Lens (Caesar a_adXF) (Caesar a_ae05) a_adXF a_ae05
- Crypto.Classical.Cipher.Enigma: enigma :: Iso (Enigma a_aged) (Enigma a_aggF) a_aged a_aggF
+ Crypto.Classical.Cipher.Enigma: enigma :: Lens (Enigma a_aejJ) (Enigma a_aemb) a_aejJ a_aemb
- Crypto.Classical.Cipher.Stream: stream :: Iso (Stream a_ai2D) (Stream a_ai6P) a_ai2D a_ai6P
+ Crypto.Classical.Cipher.Stream: stream :: Lens (Stream a_af7S) (Stream a_afai) a_af7S a_afai
- Crypto.Classical.Cipher.Substitution: substitution :: Iso (Substitution a_airH) (Substitution a_aiu7) a_airH a_aiu7
+ Crypto.Classical.Cipher.Substitution: substitution :: Lens (Substitution a_afuS) (Substitution a_afxi) a_afuS a_afxi
- Crypto.Classical.Cipher.Vigenere: vigenère :: Iso (Vigenère a_aiJO) (Vigenère a_aiMe) a_aiJO a_aiMe
+ Crypto.Classical.Cipher.Vigenere: vigenère :: Lens (Vigenère a_afMH) (Vigenère a_afP7) a_afMH a_afP7
Files
- Crypto/Classical.hs +1/−1
- Crypto/Classical/Cipher/Affine.hs +2/−1
- Crypto/Classical/Cipher/Caesar.hs +2/−1
- Crypto/Classical/Cipher/Enigma.hs +5/−4
- Crypto/Classical/Cipher/Stream.hs +2/−1
- Crypto/Classical/Cipher/Substitution.hs +2/−1
- Crypto/Classical/Cipher/Vigenere.hs +4/−3
- Crypto/Classical/Shuffle.hs +3/−3
- Crypto/Classical/Test.hs +19/−20
- Crypto/Classical/Types.hs +2/−1
- Crypto/Classical/Util.hs +1/−1
- crypto-classical.cabal +6/−5
Crypto/Classical.hs view
@@ -3,7 +3,7 @@ -- Copyright : (c) Colin Woodbury, 2015 -- License : BSD3 -- Maintainer: Colin Woodbury <colingw@gmail.com>-+-- -- A reexport of every module. module Crypto.Classical
Crypto/Classical/Cipher/Affine.hs view
@@ -15,12 +15,13 @@ module Crypto.Classical.Cipher.Affine where import Control.Applicative-import Control.Lens import Crypto.Classical.Types import Crypto.Classical.Util import qualified Data.ByteString.Lazy.Char8 as B import Data.Char import Data.Modular+import Lens.Micro+import Lens.Micro.TH ---
Crypto/Classical/Cipher/Caesar.hs view
@@ -15,12 +15,13 @@ module Crypto.Classical.Cipher.Caesar where import Control.Applicative-import Control.Lens import Crypto.Classical.Types import Crypto.Classical.Util import qualified Data.ByteString.Lazy.Char8 as B import Data.Char import Data.Modular+import Lens.Micro+import Lens.Micro.TH ---
Crypto/Classical/Cipher/Enigma.hs view
@@ -13,7 +13,6 @@ module Crypto.Classical.Cipher.Enigma where import Control.Applicative-import Control.Lens import Control.Monad.Trans.State.Lazy import Crypto.Classical.Types import Crypto.Classical.Util@@ -23,6 +22,8 @@ import qualified Data.Map.Lazy as M import Data.Maybe (fromJust) import Data.Modular+import Lens.Micro+import Lens.Micro.TH --- @@ -64,7 +65,7 @@ withInitPositions :: EnigmaKey -> EnigmaKey withInitPositions k = k & rotors .~ zipWith f (k ^. rotors) (k ^. settings) where f r s = (r & circuit %~ rotate (int s)- & turnover -~ (int s))+ & turnover %~ (\n -> n - int s)) -- | 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@@ -72,7 +73,7 @@ turn :: [Rotor] -> [Rotor] turn [] = [] turn (r:rs) = if (r' ^. turnover) == 25 then r' : turn rs else r' : rs- where r' = r & circuit %~ rotate 1 & turnover -~ 1+ where r' = r & circuit %~ rotate 1 & turnover %~ (\n -> n - 1) -- | Rotate a Rotor by `n` positions. By subtracting 1 from every key -- and value, we perfectly simulate rotation. Example:@@ -80,4 +81,4 @@ -- >>> 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)] rotate :: ℤ/26 -> Map (ℤ/26) (ℤ/26) -> Map (ℤ/26) (ℤ/26)-rotate n r = M.fromList (itoList r & traverse . both -~ n)+rotate n r = M.fromList (M.toList r & traverse . both %~ (\n' -> n' - n))
Crypto/Classical/Cipher/Stream.hs view
@@ -15,12 +15,13 @@ module Crypto.Classical.Cipher.Stream where import Control.Applicative-import Control.Lens import Crypto.Classical.Types import Crypto.Classical.Util import qualified Data.ByteString.Lazy.Char8 as B import Data.Char import Data.Modular+import Lens.Micro+import Lens.Micro.TH ---
Crypto/Classical/Cipher/Substitution.hs view
@@ -13,13 +13,14 @@ module Crypto.Classical.Cipher.Substitution where import Control.Applicative-import Control.Lens import Crypto.Classical.Types import Crypto.Classical.Util import qualified Data.ByteString.Lazy.Char8 as B import Data.Char import Data.Map.Lazy (Map) import qualified Data.Map.Lazy as M+import Lens.Micro+import Lens.Micro.TH ---
Crypto/Classical/Cipher/Vigenere.hs view
@@ -14,11 +14,12 @@ module Crypto.Classical.Cipher.Vigenere where import Control.Applicative-import Control.Lens import Crypto.Classical.Cipher.Stream import Crypto.Classical.Types import qualified Data.ByteString.Lazy.Char8 as B import Data.Modular+import Lens.Micro+import Lens.Micro.TH --- @@ -37,8 +38,8 @@ Vigenère a >>= f = f a instance Cipher [ℤ/26] Vigenère where- encrypt k m = pure . view stream . encrypt (vigKey m k) $ m- decrypt k m = pure . view stream . decrypt (vigKey m k) $ m+ encrypt k m = pure . (^. stream) . encrypt (vigKey m k) $ m+ decrypt k m = pure . (^. stream) . decrypt (vigKey m k) $ m -- | Determine a Vigenère key from a Stream key. -- Weakness here: key length is a factor of the plaintext length.
Crypto/Classical/Shuffle.hs view
@@ -1,11 +1,11 @@--- Code borrowed from `random-shuffle` and modified to match--- crypto-random data types.- -- | -- Module : Crypto.Classical.Shuffle -- Copyright : (c) Colin Woodbury, 2015 -- License : BSD3 -- Maintainer: Colin Woodbury <colingw@gmail.com>+--+-- Code borrowed from `random-shuffle` and modified to match+-- crypto-random data types. module Crypto.Classical.Shuffle (
Crypto/Classical/Test.hs view
@@ -21,8 +21,7 @@ , testAll ) where -import Control.Applicative ((<$>))-import Control.Lens+import Lens.Micro import Control.Monad (void) import Crypto.Classical.Cipher import Crypto.Classical.Letter@@ -47,24 +46,24 @@ testAll = void . sequence $ cipherTs ++ otherTs cipherTs :: [IO ()]-cipherTs = [ cycleT $ view caesar- , cycleT $ view affine- , cycleT $ view substitution- , cycleT $ view stream- , cycleT $ view vigenère- , cycleT $ view enigma- , notSelfT $ view caesar- , notSelfT $ view affine- , notSelfT $ view substitution- , notSelfT $ view stream- , notSelfT $ view vigenère- , notSelfT $ view enigma- , diffKeyT $ view caesar- , diffKeyT $ view affine- , diffKeyT $ view substitution- , diffKeyT $ view stream- , diffKeyT $ view vigenère- , diffKeyT $ view enigma+cipherTs = [ cycleT $ (^. caesar)+ , cycleT $ (^. affine)+ , cycleT $ (^. substitution)+ , cycleT $ (^. stream)+ , cycleT $ (^. vigenère)+ , cycleT $ (^. enigma)+ , notSelfT $ (^. caesar)+ , notSelfT $ (^. affine)+ , notSelfT $ (^. substitution)+ , notSelfT $ (^. stream)+ , notSelfT $ (^. vigenère)+ , notSelfT $ (^. enigma)+ , diffKeyT $ (^. caesar)+ , diffKeyT $ (^. affine)+ , diffKeyT $ (^. substitution)+ , diffKeyT $ (^. stream)+ , diffKeyT $ (^. vigenère)+ , diffKeyT $ (^. enigma) , noSelfMappingT ]
Crypto/Classical/Types.hs view
@@ -34,7 +34,6 @@ , plugFrom ) where -import Control.Lens import Crypto.Classical.Shuffle import Crypto.Classical.Util import Crypto.Number.Generate@@ -47,6 +46,8 @@ import Data.Modular import Data.Monoid ((<>)) import Data.Text (Text)+import Lens.Micro+import Lens.Micro.TH ---
Crypto/Classical/Util.hs view
@@ -26,7 +26,7 @@ , stretch ) where -import Control.Lens+import Lens.Micro import Crypto.Number.Generate import Crypto.Number.ModArithmetic (inverseCoprimes) import Crypto.Random
crypto-classical.cabal view
@@ -1,6 +1,6 @@ name: crypto-classical -version: 0.1.0+version: 0.2.0 synopsis: An educational tool for studying classical cryptography schemes. @@ -26,11 +26,11 @@ ByteStrings without worrying much about types: . > > import Crypto.Classical- > > import Control.Lens+ > > import Lens.Micro > > :set -XOverloadedStrings- > > (key <$> prng) >>= \k -> return (encrypt k "What a great day for an attack!" ^. enigma)+ > > (\k -> encrypt k "What a great day for an attack!" ^. enigma) . key <$> prng > "PXQS D KXSGB CFC AYK XJ DEGMON!"- > > (key <$> prng) >>= \k -> return (encrypt k "What a great day for an attack!" ^. caesar)+ > > (\k -> encrypt k "What a great day for an attack!" ^. caesar) . key <$> prng > "RCVO V BMZVO YVT AJM VI VOOVXF!" homepage: https://github.com/fosskers/crypto-classical@@ -81,7 +81,8 @@ , containers >= 0.5.5.1 , crypto-numbers >= 0.2.7 , crypto-random- , lens >= 4.7+ , microlens >= 0.2.0.0+ , microlens-th >= 0.2.1.1 , modular-arithmetic >= 1.2.0.0 , random , random-shuffle >= 0.0.4