-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcifrado_cesar.hs
More file actions
34 lines (26 loc) · 1.07 KB
/
cifrado_cesar.hs
File metadata and controls
34 lines (26 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module CifradoCesar where
import Data.Char (ord, chr)
encode :: Int -> Char -> Char
encode i c = chr $ ord c + i
encode_string :: Int -> [Char] -> [Char]
encode_string i s = map (\x -> encode i x) s
decode :: Int -> Char -> Char
decode i c = chr $ ord c - i
decode_string :: Int -> [Char] -> [Char]
decode_string i s = map (\x -> decode i x) s
-------------------------------------------------------------------------
encode_message :: Int -> [Char] -> [Char]
encode_message i = (map chr . map (+i) . map ord)
decode_message :: Int -> [Char] -> [Char]
decode_message i = (map chr . map (\x -> x - i) . map ord)
decode_message' :: Int -> [Char] -> [Char]
decode_message' i = encode_message (negate i)
-- book functions
encode' :: Int -> String -> String
encode' i = map (chr . (+i) . ord)
-- pienso que se llega a esta forma porque:
-- 1.- programación funcional deriva de matemáticas, por lo tanto esto es una simple factorización.
-- 2.- existen ciertas reglas de la notación Point Free que aún desconozco.
--
decode' :: Int -> String -> String
decode' i s = encode' (negate i) s