I've been working in an algorithm that I found in this link: Pure Lua implementation of md5 to use in an embedded system, but it uses strings as input.
For my specific application, the hash need to receive an hex array like that: 85202599ee7e0165ee32be43336755595955544554554747.
How can I change the function bellow to calculate the hash using the array above?
function md5.Calc(s)
local msgLen=string.len(s)
local padLen=56- msgLen % 64
if msgLen % 64 > 56 then padLen=padLen+64 end
if padLen==0 then padLen=64 end
s=s..string.char(128)..string.rep(string.char(0),padLen-1)
s=s..leIstr(8*msgLen)..leIstr(0)
assert(string.len(s) % 64 ==0)
local t=md5.consts
local a,b,c,d=t[65],t[66],t[67],t[68]
for i=1,string.len(s),64 do
local X=leStrCuts(string.sub(s,i,i+63),4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4)
assert(#X==16)
X[0]=table.remove(X,1) -- zero based!
a,b,c,d=md5.transform(a,b,c,d,X)
end
local swap=function (w) return beInt(leIstr(w)) end
return string.format("%08x%08x%08x%08x",swap(a),swap(b),swap(c),swap(d))
end
return md5.Calc("85202599ee7e0165ee32be43336755595955544554554747"); -- returns: cc238dfd3cf48d588714774efeaf9a1f
-- but I need a return like that calculated in https://cryptii.com/pipes/md5-hash: c7e9f863554dc9a410c414f8758b307d