Sha256: 82cd5ca238d80c5d2e882672ed07bc7b1be371a0c01b2a8464fae42f15465936
Contents?: true
Size: 494 Bytes
Versions: 396
Compression:
Stored size: 494 Bytes
Contents
class Atbash def self.encode(plaintext) new(plaintext).encode end attr_reader :plaintext def initialize(plaintext) @plaintext = plaintext end def encode chunk convert(normalize(plaintext)) end private def convert(s) s.tr(alphabet, key) end def chunk(s) s.scan(/.{1,5}/).join(' ') end def normalize(s) s.downcase.gsub(/[^a-z0-9]/, '') end def alphabet 'abcdefghijklmnopqrstuvwxyz' end def key alphabet.reverse end end
Version data entries
396 entries across 396 versions & 1 rubygems