Skip to content

Instantly share code, notes, and snippets.

@thatrubylove thatrubylove/rot13.rb
Last active Oct 15, 2015

Embed
What would you like to do?
ROT13 in Ruby
require 'byebug'
module Rot13
extend self
LOWERS = ("a".."z").to_a
UPPERS = ("A".."Z").to_a
def cypher(val)
val.to_s.chars.map do |ch|
cypher_char(ch, LOWERS) ||
cypher_char(ch, UPPERS) ||
ch
end.join
end
alias_method :decypher, :cypher
private
def cypher_char(val, array)
return unless index = array.index(val)
array.reverse[index-13]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.