Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Caesar-cipher/Ela/caesar-cipher.ela
Normal file
28
Task/Caesar-cipher/Ela/caesar-cipher.ela
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
open number char monad io string
|
||||
|
||||
chars = "ABCDEFGHIJKLMOPQRSTUVWXYZ"
|
||||
|
||||
caesar _ _ [] = ""
|
||||
caesar op key (x::xs) = check shifted ++ caesar op key xs
|
||||
where orig = indexOf (string.upper $ toString x) chars
|
||||
shifted = orig `op` key
|
||||
check val | orig == -1 = x
|
||||
| val > 24 = trans $ val - 25
|
||||
| val < 0 = trans $ 25 + val
|
||||
| else = trans shifted
|
||||
trans idx = chars:idx
|
||||
|
||||
cypher = caesar (+)
|
||||
decypher = caesar (-)
|
||||
|
||||
key = 2
|
||||
|
||||
do
|
||||
putStrLn "A string to encode:"
|
||||
str <- readStr
|
||||
putStr "Encoded string: "
|
||||
cstr <- return <| cypher key str
|
||||
put cstr
|
||||
putStrLn ""
|
||||
putStr "Decoded string: "
|
||||
put $ decypher key cstr
|
||||
Loading…
Add table
Add a link
Reference in a new issue