File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ #DCTf569 - Rot13
2
+ #alphabet[alphabet.index('')+ 13 - 26]
3
+ require 'pry'
4
+ def rot13 ( sentence )
5
+ alphabet = ( 'a' ..'z' ) . to_a
6
+ letters = sentence . split ( "" ) # ["t", "e", "s", "t"]
7
+ #new sentence = []
8
+ new_sentence = ""
9
+ binding . pry
10
+ letters . each do |letter |
11
+ binding . pry
12
+ if letter != ' ' # if there is no space in the sentence then find the index
13
+ index_of = alphabet . index ( letter . downcase )
14
+ binding . pry
15
+ char_index = index_of + 13 - 26
16
+ #new_sentence.push(alphabet[char_index])
17
+ new_letter = alphabet [ char_index ]
18
+ new_sentence += ( letter == letter . upcase ) ? new_letter .
19
+ upcase : new_letter
20
+ else # if there is a space in the sentence then add a empty space
21
+ new_sentence += ' '
22
+ end
23
+ end
24
+ #return new_sentence
25
+ return new_sentence
26
+ end `
27
+
28
+ puts "Enter a sentence"
29
+ sentence = gets . chomp # "test"
30
+
31
+ result = rot13 ( sentence ) #"test"
32
+ puts result
You can’t perform that action at this time.
0 commit comments