Quick actions

cmd+k|ctrl+k

Navigation

Languages

Caesar Cipher

Snippet info

Language

Haskell

Visibility

public

Author

kaspik99

Created

2019-01-16T15:48:15Z

Updated

2019-01-16T17:21:15Z

-- https://cryptii.com/pipes/caesar-cipher

import Data.Char


cipher :: [Char] -> Int -> [Char]
cipher [] _ = []
cipher (x:xs) n = (if x `elem` chars
                        then (chars !! (rem (n + (ind x)) nchars))
                        else x) : (cipher xs n)
    where
        ind x = (ord x) - 97
        chars = ['a'..'z']
        nchars = length chars

-- Prelude> cipher "hello" 13
-- "uryyb"

main = putStrLn $ cipher "hello" 13
INFO