-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex_002.rb
More file actions
85 lines (65 loc) · 1.74 KB
/
ex_002.rb
File metadata and controls
85 lines (65 loc) · 1.74 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
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
79
80
81
82
83
#!/usr/bin/ruby
# Mubashir Cipher
# In Mubashir Cipher, encoding is done by simply replacing paired
# alphabets from the provided key.
#
# Create a function that takes a string containing the message
# to be encoded with a fixed given 2D array of alphabets key.
#
# There are some variations on the rules of encipherment.
# One version of the cipher rules are outlined below:
#
# key = [['m', 'c'], ['u', 'e'], ['b', 'g'], ['a', 'k'],
# ['s', 'v'], ['h', 'x'], ['i', 'z'], ['r', 'y'],
# ['p', 'w'], ['l', 'n'], ['o', 'j'], ['t', 'f'], ['q', 'd']]
# message = "edabit is amazing !"
# mubashir_cipher(message) ➞ "uqkgzf zv kckizlb !"
# https://edabit.com/challenge/8W5AHdDGHfPf2GW6y
class Cipher_Text
def initialize(*message)
#String
@message = message
#Array
@encoded = Array.new
end
def set(message)
@message = message
end
def mubashir_cipher()
key = [
['m', 'c'],
['u', 'e'],
['b', 'g'],
['a', 'k'],
['s', 'v'],
['h', 'x'],
['i', 'z'],
['r', 'y'],
['p', 'w'],
['l', 'n'],
['o', 'j'],
['t', 'f'],
['q', 'd']
]
aux = Array.new
aux = @message.downcase.split("")
@encoded.clear
for i in aux do
for j in key do
if i == j[0]
i = j[1]
elsif i == j[1]
i = j[0]
end
end
@encoded.append(i)
end
end
def get()
"#{@encoded.join}"
end
end
cipher_text = Cipher_Text.new
cipher_text.set(gets())
cipher_text.mubashir_cipher()
puts cipher_text.get()