class Cryptogram

Constants

ALPHABET

Attributes

cyphertext[R]
key[R]
plaintext[R]

Public Class Methods

new(plaintext) click to toggle source
# File lib/cryptograms/cryptogram.rb, line 5
def initialize plaintext
  @plaintext = plaintext.upcase
  @cyphertext = @plaintext.tr ALPHABET.join, cypher.join
end

Public Instance Methods

cypher() click to toggle source

Randomize until no cyphertext replacement is the same as the original letter.

# File lib/cryptograms/cryptogram.rb, line 12
def cypher
  loop do
    (@key ||= ALPHABET.dup).shuffle!
    redo if @key.zip(ALPHABET).any? { |k, v| k == v }
    return @key
  end
end

Private Instance Methods

rosetta_stone() click to toggle source
# File lib/cryptograms/cryptogram.rb, line 22
def rosetta_stone
  ALPHABET.zip @key
end