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



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cobreak/cifrado.rb', line 9

def self.cipher(mode, dato)
  cipher = OpenStruct.new
  cipher.mode = mode
  cipher.dato = dato
  if (cipher.mode.eql?('base16'))
    cipher.result = Base16.encode16(dato)
  elsif (cipher.mode.eql?('base32'))
    cipher.result = Base32.encode(dato)
  elsif (cipher.mode.eql?('base64'))
    cipher.result = Base64.encode64(dato)
  elsif (cipher.mode.eql?('ascii85'))
    cipher.result = Ascii85.encode(dato)
  elsif (cipher.mode.eql?('cesar'))
    cipher.result = Cesar.cesar(dato, ARGV[0].to_i)
  elsif (cipher.mode.eql?('binary'))
    cipher.result = CoBreak::Binary.binary(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