module Exercise_12 where import Data.List -- (nub) import Data.Maybe {-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-} encrypt :: String -> String encrypt ws= map (ws!!) $table $length ws --table :: Int -> [Int] table n= map pred $primes n ++ (enumFromTo 1 n \\ primes n) decrypt :: String -> String decrypt ws= map fst $sortOn snd $zip ws $table $ length ws {-TTEW-}