Module: ImageCipher

Defined in:
src/image_cipher.rb

Overview

Cifrador de imagenes BMP.

Class Method Summary collapse

Class Method Details

.process(path, key, iv, out: 'out.bmp') ⇒ Object

Cifra una imagen BMP.

Parameters:

  • path (String)

    ruta de la imagen.

  • key (String | Numeric | Word)

    clave de 128 bits.

  • iv (String | Numeric | Word)

    vector de inicialización de 128 bits.

  • out (String)

    el nombre del archivo de salida.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'src/image_cipher.rb', line 14

def process(path, key, iv, out: 'out.bmp')
  image_url = nil
  body = nil

  File.open(path) do |file|
    image_url = file.read(54).bytes
    body = file.read.bytes
  end

  mugi = MUGI.new(key, iv)
  size = body.size.fdiv(8).ceil

  size.times do |n|
    image_url.concat((Word.new(body[n * 8, 8]). mugi.next).partition(8).map(&:to_i))
  end

  File.open(out, 'w') { |f| f.write(image_url.pack('c*')) }
end