Initial catchat commit.
This commit is contained in:
commit
8b30fe923c
9 changed files with 460 additions and 0 deletions
51
decode_image.rb
Normal file
51
decode_image.rb
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue