Module: GravityFallsMessage

Defined in:
lib/gravity_falls_message.rb,
lib/gravity_falls_message/cipher.rb,
lib/gravity_falls_message/version.rb

Defined Under Namespace

Classes: Cipher

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.decode(message, cipher, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/gravity_falls_message.rb', line 6

def self.decode message, cipher, options={}
  if  cipher != 'binary'
    message = cipher == 'a1z26' ? message.split(/( |\W)/) : message.split('')
  end
  # raise something if cipher == 'vigenere' && options[:key].nil?
  case cipher
  when 'a1z26' then Cipher.a1z26(message)
  when 'atbash' then Cipher.atbash(message)
  when 'binary' then Cipher.binary(message)
  when 'caesar' then Cipher.caesar(message, options)
  when 'rotated_caesar' then Cipher.rotated_caesar(message, options)
  when 'vigenere' then Cipher.vigenere(message, options)
  end
end

.encode(message, cipher, options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gravity_falls_message.rb', line 21

def self.encode message, cipher, options={}
  message = message.split(//) if cipher != 'binary'

  case cipher
  when 'a1z26' then Cipher.a1z26(message, true)
  when 'atbash' then Cipher.atbash(message, true)
  when 'binary' then Cipher.binary(message, true)
  when 'caesar' then Cipher.caesar(message, options.merge(encode: true))
  when 'vigenere' then Cipher.vigenere(message, options.merge(encode: true))
  end
end