Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
24
Task/Caesar-cipher/Haskell/caesar-cipher-2.hs
Normal file
24
Task/Caesar-cipher/Haskell/caesar-cipher-2.hs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import Data.Bool (bool)
|
||||
import Data.Char (chr, isAlpha, isUpper, ord)
|
||||
|
||||
---------------------- CAESAR CIPHER ---------------------
|
||||
|
||||
caesar, uncaesar :: Int -> String -> String
|
||||
caesar = fmap . tr
|
||||
uncaesar = caesar . negate
|
||||
|
||||
tr :: Int -> Char -> Char
|
||||
tr offset c
|
||||
| isAlpha c =
|
||||
chr
|
||||
. ((+) <*> (flip mod 26 . (-) (offset + ord c)))
|
||||
$ bool 97 65 (isUpper c)
|
||||
| otherwise = c
|
||||
|
||||
--------------------------- TEST -------------------------
|
||||
main :: IO ()
|
||||
main = do
|
||||
let k = -114
|
||||
cipher = caesar k
|
||||
plain = "Curio, Cesare venne, e vide e vinse ? "
|
||||
mapM_ putStrLn $ [cipher, uncaesar k . cipher] <*> [plain]
|
||||
Loading…
Add table
Add a link
Reference in a new issue