module Exercise_12 where import Data.List (nub, partition, permutations) import Data.Bifoldable import Control.Arrow 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 = zip (enumFrom 1) >>> biconcat . partition (isPrime . fst) >>> map snd decrypt :: String -> String decrypt s = until ((s ==) . encrypt) encrypt s {-TTEW-}