-
Notifications
You must be signed in to change notification settings - Fork 0
/
Caesar.fold
79 lines (61 loc) · 1.6 KB
/
Caesar.fold
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
-- F#
-- http://www.rosettacode.org/wiki/Caesar_cipher#F.23
module caesar =
open System
let cipher n s =
let shift c =
if Char.IsLetter c then
let a = int (if Char.IsLower c then 'a' else 'A')
char ((int c - a + n) mod 26 + a)
else c
String.map shift s
let encrypt n = cipher n
let decrypt n = cipher (26 - n)
-- OCaml
module caesar = struct
open System
let cipher n s =
let shift c =
if Char.IsLetter c then
let a = int (if Char.IsLower c then 'a' else 'A') in
char ((int c - a + n) mod 26 + a)
else c in
String.map shift s
let encrypt n = cipher n
let decrypt n = cipher (26 - n)
end
-- Fold
module Caesar =
open System
def cipher n s =
let shift c =
if Char.is_letter c then
a = int (Char.is_lower c ? 'a' : 'A')
a = int ('a' if Char.is_lower c else 'A')
a = int (if (Char.is_lower c) 'a' else 'A')
a = int (if Char.is_lower c then 'a' else 'A')
a = int (if (Char.is_lower c) 'a' else 'A' end)
a = int (if Char.is_lower c -> 'a' | else -> 'A')
a = int (if Char.is_lower c then 'a' else 'A' end)
char ((int c - a + n) mod 26 + a)
else
c
end
map shift s
def encrypt n = cipher n
def decrypt n = cipher (26 - n)
-- Fold
module Caesar
open System
def cipher n s =
let shift c =
if Char.is_letter c
a = int (if Char.is_lower c -> 'a' | else -> 'A')
char ((int c - a + n) mod 26 + a)
else
c
end in
map shift s
def encrypt n = cipher n
def decrypt n = cipher (26 - n)
end