forked from turingschool-examples/backend_mod_1_prework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathceasar_cipher.rb
70 lines (45 loc) · 1.12 KB
/
ceasar_cipher.rb
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
# cipher = CeasarCipher.new
# cipher.encode("Hello World", 5)
# class CeasarCipher
#
# def encode(input)
# puts input.chars
def hash_builder letters, number
hash = Hash.new
letters.each_with_index do |letter, index|
hash[letter] = number[index]
end
hash
end
a_z = [*"a".."z"]
positive = [*0..25]
negative = [*-26..-1]
x = hash_builder a_z, positive
y = hash_builder negative, a_z
z = hash_builder positive, a_z
ryan = "Hello World"
new_arry = ryan.downcase.scan /\w/
new_arry.each do |letters|
numbers = x[letters]
new_numbers = numbers - 10
if new_numbers >= 0
puts z[new_numbers]
elsif new_numbers < 0
puts y[new_numbers]
end
end
# end
#
# end
#
# cipher = CeasarCipher.new
# cipher.encode("Hello World")
#
# ryan = "hello ryan"
# A method that takes a string, divides into characters, and converts those characters into integers
# def encode string
# puts string.chars
#
# end
# ryan.encode
# we need to iterate over the new array or elements and assign values based on a hash