-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcipher.rb
More file actions
34 lines (25 loc) · 772 Bytes
/
cipher.rb
File metadata and controls
34 lines (25 loc) · 772 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
def caesar_cipher(text, amount = 0)
deciphered = ""
text.each_char do |char|
num = char.ord
num += amount
num -= 26 if num > 122
new_char = num.chr
deciphered << new_char
end
deciphered
end
def skull_cipher(text, word = "skull", deciphered = "", count = 0, idx = 0)
return deciphered if idx >= text.length
count = 0 if count > word.length - 1
num = word[count].ord - 97
char = text[idx]
deciphered << caesar_cipher(char, num)
skull_cipher(text, word, deciphered, count += 1, idx += 1)
end
puts caesar_cipher("vbyjpwoly", 19)
puts skull_cipher("aaaaa")
moo = skull_cipher("klkbnqlcytfysryucocphg")
puts moo
puts caesar_cipher(moo, 24)
#26.times {|num| puts caesar_cipher(skull_cipher("klkbnqlcytfysryucocphg"), num + 1) }