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

Version Path
trackler-2.0.0.5 tracks/ruby/exercises/atbash-cipher/example.rb
trackler-2.0.0.4 tracks/ruby/exercises/atbash-cipher/example.rb
trackler-2.0.0.3 tracks/ruby/exercises/atbash-cipher/example.rb
trackler-2.0.0.2 tracks/ruby/exercises/atbash-cipher/example.rb
trackler-2.0.0.1 tracks/ruby/exercises/atbash-cipher/example.rb
trackler-2.0.0.0 tracks/ruby/exercises/atbash-cipher/example.rb
trackler-1.0.4.1 tracks/ruby/exercises/atbash-cipher/example.rb
trackler-1.0.4.0 tracks/ruby/exercises/atbash-cipher/example.rb
trackler-1.0.3.0 tracks/ruby/exercises/atbash-cipher/example.rb
trackler-1.0.2.1 tracks/ruby/exercises/atbash-cipher/example.rb
trackler-1.0.2.0 tracks/ruby/exercises/atbash-cipher/example.rb
trackler-1.0.1.2 tracks/ruby/exercises/atbash-cipher/example.rb
trackler-1.0.1.1 tracks/ruby/exercises/atbash-cipher/example.rb
trackler-1.0.1.0 tracks/ruby/exercises/atbash-cipher/example.rb
trackler-1.0.0.1 tracks/ruby/exercises/atbash-cipher/example.rb
trackler-1.0.0 tracks/ruby/exercises/atbash-cipher/example.rb