Class: CoBreak::Cifrado

Inherits:
Object
  • Object
show all
Defined in:
lib/cobreak/cifrado.rb

Class Method Summary collapse

Class Method Details

.cipher(mode, dato) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cobreak/cifrado.rb', line 5

def self.cipher(mode, dato)
  cipher = OpenStruct.new
  cipher.mode = mode
  cipher.dato = dato
  if (cipher.mode.eql?('base16'))
    cipher.result = CoBreak::Cipher::Base16.encode(dato)
  elsif (cipher.mode.eql?('base32'))
    cipher.result = CoBreak::Cipher::Base32.encode(dato)
  elsif (cipher.mode.eql?('base64'))
    cipher.result = CoBreak::Cipher::Base64.encode(dato)
  elsif (cipher.mode.eql?('ascii85'))
    cipher.result = Ascii85.encode(dato)
  elsif (cipher.mode.eql?('cesar'))
    cipher.result = CoBreak::Cipher::Cesar.encode(dato, ARGV[0].to_i)
  elsif (cipher.mode.eql?('binary'))
    cipher.result = CoBreak::Cipher::Binary.encode(dato)
  end
  unless (cipher.result.nil?) or (cipher.result.eql?(cipher.dato))
    puts "\n\e[1;32m[\e[37m+\e[1;32m]\e[37m Ciphertext: #{cipher.result}"
    puts "\e[1;32m[\e[37m+\e[1;32m]\e[37m Number Rotations: #{ARGV[0]}" if (cipher.mode.eql?('cesar'))
  else
    puts "\e[1;31m[\e[37m+\e[1;31m]\e[37m Not Cipher Text..."
  end
end