Sha256: db25d087df0daa205255c3eae31c667df9fbb07bf26905dc9bc736d5ab8160ce
Contents?: true
Size: 1.05 KB
Versions: 2
Compression:
Stored size: 1.05 KB
Contents
module Gap MD5_INIT = Win32API.new("ADVAPI32", "MD5Init", "p", "L") MD5_UPDATE = Win32API.new("ADVAPI32", "MD5Update", "ppL", "L") MD5_FINAL = Win32API.new("ADVAPI32", "MD5Final", "p", "L") class MD5 def initialize @ctx = "\0" * 128 # buf MD5_INIT.call(@ctx) end def update(str) MD5_UPDATE.call(@ctx, str, str.unpack("C*").size) end def digest MD5_FINAL.call(@ctx) @ctx[88, 16] end def self.digest(a) x = MD5.new x.update a x.digest end def self.hexdigest(a) digest(a).unpack("H*").first end def self.file(fn) open(fn, 'rb') do |f| x = MD5.new while (r = f.read(10240)) x.update(r) end x.digest end end def self.filehex(fn) file(fn).unpack("H*").first end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gap50-0.1.1 | lib/gap50/samsara/md5.rb |
gap50-0.1.0 | lib/gap50/samsara/md5.rb |