-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencryptor.rb
More file actions
36 lines (28 loc) · 791 Bytes
/
encryptor.rb
File metadata and controls
36 lines (28 loc) · 791 Bytes
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
class Encryptor
def encrypt(string)
letters = string.split("")
results = []
letters.collect do |letter|
encrypted_letter = encrypt_letter(letter)
results.push(encrypted_letter)
end
results.join
end
def encrypt_letter(letter)
lowercase_letter = letter.downcase
cipher[lowercase_letter]
end
def cipher
{"a" => "n", "b" => "o", "c" => "p", "d" => "q",
"e" => "r", "f" => "s", "g" => "t", "h" => "u",
"i" => "v", "j" => "w", "k" => "x", "l" => "y",
"m" => "z", "n" => "a", "o" => "b", "p" => "c",
"q" => "d", "r" => "e", "s" => "f", "t" => "g",
"u" => "h", "v" => "i", "w" => "j", "x" => "k",
"y" => "l", "z" => "m"}
end
def decrypt(string)
letters = string.split("")
results = []
lettters.collecect
end