Last active
August 29, 2015 14:21
-
-
Save santouras/3ad609038e4dcac9c811 to your computer and use it in GitHub Desktop.
atbash
This file contains 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 characters
class Atbash | |
ARR = ('a'..'z').to_a | |
def self.encode str | |
str. | |
downcase. | |
each_char.map { |c| cipher(c) }.join. | |
scan(/.{1,5}/).join(" ") | |
end | |
private | |
def self.cipher char | |
return char if ('0'..'9').include? char | |
return ARR.reverse[ARR.index(char)] if ARR.include?(char) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment