forked from codeunion/ruby-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrot13.rb
More file actions
29 lines (24 loc) · 1.01 KB
/
rot13.rb
File metadata and controls
29 lines (24 loc) · 1.01 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
# Method name: rot13
# Inputs: A String to be encoded in ROT13
# Returns: A ROT13-encoded string
# Prints: Nothing
# ROT13 is short for "rotate 13" and is the simplest example of a "Caesar cipher".
# See http://en.wikipedia.org/wiki/ROT13
# ROT13 works by taking a string and "rotating" all the characters in that
# string 13 places to the right in the alphabet, with "z" wrapping around to
# the beginning of the alphabet.
#
# In other words, every letter from the top row in this table is replaced with
# the corresponding letter in the bottomr row
#
# ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
# NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm
#
# "ROT13" is called a Caesar cipher because Julius Caesar used such letter
# replacement schemes to "encrypt" his communication.
def rot13(string)
end
if __FILE__ == $0
# See http://www.rot-n.com/ to generate test inputs and outputs
p rot13("The Quick Brown Fox Jumps Over The Lazy Dog") == "Gur Dhvpx Oebja Sbk Whzcf Bire Gur Ynml Qbt"
end