Created
July 13, 2015 08:11
-
-
Save AlexanderFisenko/ec89de6d9cd0296f062f to your computer and use it in GitHub Desktop.
Revisions
-
AlexanderFisenko created this gist
Jul 13, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ def rot13(string) a = 'a'.ord z = 'z'.ord capital_a = 'A'.ord capital_z = 'Z'.ord decyphered_string = "" string.unpack('c*').each do |char| if (a..z).cover?(char) modified_char = (((char - a) + 13) % 26) + a decyphered_string << [modified_char].pack('c*') elsif (capital_a..capital_z).cover?(char) modified_char = (((char - capital_a) + 13) % 26) + capital_a decyphered_string << [modified_char].pack('c*') else decyphered_string << char end end decyphered_string end