-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
77 lines (72 loc) · 1.31 KB
/
main.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
71
72
73
74
75
76
77
def menu
puts "-" * 55
puts "[1]. Caesar cipher crack\n[2]. Caesar cipher encryption\n[3]. Caesar cipher decryption\n[4]. Exit"
puts "-" * 55
puts "What you want to do?"
choice = gets.chomp
case choice
when "1"
caesar_crack()
when "2"
caesar_encryption()
when "3"
caesar_decryption()
when "4"
exit
else
puts "'#{choice}': is invalid"
end
end
def caesar_decryption
puts "Insert your text here."
txt = gets.chomp
puts "Insert cipher key"
key = gets.chomp.to_i
txt.scan(/./)
len = txt.length
result = ""
len.times do |i|
result += (txt[i].ord - key).chr
end
puts '-' * 55
puts result
menu()
end
def caesar_encryption
puts "Insert your text here."
txt = gets.chomp
puts "Insert cipher key"
key = gets.chomp.to_i
txt.scan(/./)
len = txt.length
result = ""
len.times do |i|
result += (txt[i].ord + key).chr
end
puts '-' * 55
puts result
menu()
end
def caesar_crack
puts "Insert your text here."
txt = gets.chomp
txt.scan(/./)
len = txt.length
result = ""
j = 1
k = 1
puts "-" * 55
while j <= 25 do
while k <= 25 do
len.times do |i|
result += (txt[i].ord - j).chr
end
puts "[#{k}]: #{result}\n"
puts "-" * 55 + "\n"
j += 1
k += 1
result = ""
end
end
end
menu