module Exercise_12 where 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-} {-MCCOMMENT This is my actual submission for the Competition. It timed out encrypt :: String -> String encrypt = gEncrypt gEncrypt list = getP True ++ getP False where getP b = [list!!(c-1) | c <- [1..length list], isPrime c == b] decrypt :: String -> String decrypt message = [message!! head[j | j <-indices, v == gEncrypt indices!!j] | v<-indices] where indices = [0..length message - 1] -} --Below is not the submission for the competition encrypt :: String -> String encrypt = gEncrypt gEncrypt list = getP True ++ getP False where getP b = [list!!(c-1) | c <- [1..length list], isPrime c == b] decrypt :: String -> String decrypt message = [message!!i | v<-[0..lastIndex], let i = find v] where lastIndex = length message - 1 find v = head[j | j <-[0..lastIndex], v == genc!!j] genc = gEncrypt [0.. lastIndex] {-TTEW-}