module Exercise_12 where import Data.List (nub,permutations,sortOn) import Data.Function {-H12-} isPrime :: Int -> Bool isPrime n | n <= 1 = False | otherwise = primeAux (n-1) where primeAux 1 = True primeAux i = n `mod` i /= 0 && primeAux (i-1) -- returns all primes up to the passed number primes :: Int -> [Int] primes n = [i | i<-[2..n], isPrime i] {-WETT-} f = map fst . nub theMaster = [1..] encrypt :: String -> String encrypt s = f $ filter (isPrime.snd) str ++ str where str = zip s theMaster decrypt :: String -> String decrypt s = f $ sortOn snd $ zip s $ nub $ primes (length s) ++ theMaster {-TTEW-}