-
Notifications
You must be signed in to change notification settings - Fork 0
/
MascModule.hs
31 lines (23 loc) · 962 Bytes
/
MascModule.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module MascModule
(Direction (..)
, MascKey
, masc
, initializeMascGenome
) where
import Data.Maybe (fromMaybe)
-- the charList schould always be the cleartextversion of the alphabet
import NaturalLanguageModule(charList)
import Reordering (initializePermutatedGenome)
import TypeModule (Genome, Rand, Direction(..), MascKey)
fallbackChar :: Char
fallbackChar = '_'
masc :: Direction -> MascKey -> String -> String
masc direction key = map (mascOne direction key)
mascOne :: Direction -> MascKey -> Char -> Char
mascOne Encrypt key = justLookup (zip charList key) fallbackChar
mascOne Decrypt key = justLookup (zip key charList) fallbackChar
justLookup :: (Eq a) => [(a,b)] -> b -> a -> b
justLookup list defaultValue key = fromMaybe defaultValue (lookup key list)
-- TODO: Better guesses for initialisation
initializeMascGenome :: Int -> Rand [Genome Char]
initializeMascGenome populationSize = initializePermutatedGenome populationSize charList