A much better commit of the raw rmagick access. Huge time improvement for calculating the salt.
This commit is contained in:
parent
0b26d83313
commit
e10bedee0f
4 changed files with 51 additions and 93 deletions
|
|
@ -1,65 +1,65 @@
|
|||
require "./pixel_image.rb"
|
||||
require "rmagick"
|
||||
require "digest"
|
||||
|
||||
class ImageUtils
|
||||
@@magickImg = nil
|
||||
@@pixelImg = nil
|
||||
|
||||
@@password = ""
|
||||
@@message = ""
|
||||
|
||||
@@hash = nil
|
||||
|
||||
def initialize(pass, msg, i)
|
||||
@@width = 0
|
||||
@@height = 0
|
||||
|
||||
@@pixel_arr = []
|
||||
|
||||
def initialize(pass, msg, uri)
|
||||
@@password = pass
|
||||
@@message = msg
|
||||
@@salt = 0
|
||||
|
||||
@@magickImg = Magick::Image.read(uri).first
|
||||
|
||||
@@width = @@magickImg.columns
|
||||
@@height = @@magickImg.rows
|
||||
|
||||
@@pixel_arr = @@magickImg.get_pixels(0, 0, @@width, @@height)
|
||||
|
||||
if msg.length > 1024 then
|
||||
puts "Maximum length exceeded. Exiting."
|
||||
exit
|
||||
end
|
||||
|
||||
@@magickImg = i
|
||||
|
||||
@@pixelImg = PixelImage.new(@@magickImg)
|
||||
|
||||
self.generateHash
|
||||
end
|
||||
|
||||
def getImage
|
||||
return @@pixelImg
|
||||
def getPixel(x, y)
|
||||
loc = (y*@@width) + x
|
||||
|
||||
return @@pixel_arr[loc]
|
||||
end
|
||||
|
||||
def getSalt
|
||||
for x in 0..@@width-1
|
||||
for y in 0..@@height-1
|
||||
pix = self.getPixel(x, y)
|
||||
|
||||
@@salt = @@salt + (pix.red/512)
|
||||
@@salt = @@salt + (pix.green/512)
|
||||
@@salt = @@salt + (pix.blue/512)
|
||||
end
|
||||
end
|
||||
|
||||
h = Digest::SHA512.hexdigest(@@salt.to_s(16))
|
||||
|
||||
return h
|
||||
end
|
||||
|
||||
def generateHash
|
||||
h = Digest::SHA512.hexdigest(@@password)
|
||||
s = @@pixelImg.getSalt
|
||||
pass_h = Digest::SHA512.hexdigest(@@password)
|
||||
|
||||
@@hash = Digest::SHA512.hexdigest(self.interlaceHash(h, s))
|
||||
end
|
||||
|
||||
def interlaceHash(h1, h2)
|
||||
puts h1
|
||||
puts h2
|
||||
|
||||
h1 = self.getBits(h1)
|
||||
h2 = self.getBits(h2)
|
||||
|
||||
interlaced = 0
|
||||
|
||||
while h1.to_i > 0 and h2.to_i > 0 do
|
||||
interlaced = (interlaced << 1) | (h1 & 1)
|
||||
h1 = h1 >> 1
|
||||
interlaced = (interlaced << 1) | (h2 & 1)
|
||||
h2 = h2 >> 1
|
||||
|
||||
# puts interlaced
|
||||
# puts h1
|
||||
# puts h2
|
||||
end
|
||||
|
||||
puts interlaced.to_s.inspect
|
||||
|
||||
return interlaced.to_s
|
||||
@@hash = Digest::SHA512.hexdigest(pass_h + @@salt.to_s)
|
||||
end
|
||||
|
||||
def generateLookupTable
|
||||
|
|
@ -113,4 +113,4 @@ class ImageUtils
|
|||
|
||||
return msg_bits
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue