class DecodeImage
  @@password = ""
  @@utils

  def initialize(pass, image)
    @@password = pass

    # initializing utils...
    @@utils = ImageUtils.new(@@password, image)

    @@table = @@utils.generateLookupTable
  end

  def decode
    s = @@utils.getImage.getSize

    msg_bits = 0

    @@table.reverse.each do |loc|
      pixel = @@utils.getImage.getPixel(loc[:x], loc[:y])
      msg_bits = (msg_bits << 6) | pixel.decodeBits
    end

#this trash needs to move somewhere...
puts "Try to convert the message..."
    len = msg_bits & 0xffff
    msg_bits = msg_bits >> 16

    # check the padding bits....
    if (msg_bits & 255) != 0 then
puts "Padding failed scrutiny! "
puts msg_bits.to_s(2)
      return false
    end

    msg_bits = msg_bits >> 8

puts "Padding passed scrutiny..."
    msg_chars = []

    while msg_bits > 0 do
      byte = msg_bits & 0xff
      msg_chars.push(byte.chr)
      msg_bits = msg_bits >> 8
    end

    msg = msg_chars.reverse.join

    return msg
  end
end