Skip to content

Commit 50f14fa

Browse files
committed
exercism 79 Rotational Cipher
1 parent 5f2ae8b commit 50f14fa

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ solution of many challenges of [Leetcode](https://leetcode.com/), [Exercism](htt
304304
76. [List Ops](https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/blob/master/exercism/list_ops.rb)
305305
77. [Simple Linked List](https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/blob/master/exercism/simple_linked_list.rb)
306306
78. [Binary Search Tree](https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/blob/master/exercism/binary_search_tree.rb)
307+
79. [Rotational Cipher](https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/blob/master/exercism/rotational_cipher.rb)
307308

308309
<a name="leetcode"/>
309310

exercism/rotational_cipher.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Problem: https://exercism.org/tracks/ruby/exercises/rotational-cipher
2+
3+
# Solution
4+
class RotationalCipher
5+
LETTERS = ("a".."z").to_a
6+
7+
def self.rotate(input,key)
8+
ciphertext=""
9+
input.chars.each do |char|
10+
if LETTERS.include?(char)
11+
ciphertext+=LETTERS[(LETTERS.index(char)+key)%26]
12+
elsif LETTERS.include?(char.downcase)
13+
ciphertext+=LETTERS[(LETTERS.index(char.downcase)+key)%26].upcase
14+
else
15+
ciphertext+=char
16+
end
17+
end
18+
ciphertext
19+
end
20+
end

0 commit comments

Comments
 (0)