Files
2025-10-27 20:08:04 +02:00

28 lines
7.8 KiB
Lua

-- md5.lua by kikito
-- Minified with luamin
-- Original: https://github.com/kikito/md5.lua
local a={_VERSION="md5.lua 1.1.0",_DESCRIPTION="MD5 computation in Lua (5.1-3, LuaJIT)",_URL="https://github.com/kikito/md5.lua",_LICENSE=[[
MIT LICENSE
Copyright (c) 2013 Enrique García Cota + Adam Baldwin + hanzao + Equi 4 Software
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]}local b,c,d,e,f=string.char,string.byte,string.format,string.rep,string.sub;local g,h,i,j,k,l;local m,n=pcall(require,'bit')local o,p=pcall(require,'ffi')if m then g,h,i,j,k,l=n.bor,n.band,n.bnot,n.bxor,n.rshift,n.lshift else m,n=pcall(require,'bit32')if m then i=n.bnot;local q=function(r)return r<=0x7fffffff and r or-(i(r)+1)end;local s=function(t)return function(u,v)return q(t(q(u),q(v)))end end;g,h,j=s(n.bor),s(n.band),s(n.bxor)k,l=s(n.rshift),s(n.lshift)else local function w(x)local y=0;local z=1;for A=1,#x do y=y+x[A]*z;z=z*2 end;return y end;local function B(C,D)local E,F=C,D;if#E<#F then E,F=F,E end;for A=#F+1,#E do F[A]=0 end end;local G;i=function(r)local x=G(r)local H=math.max(#x,32)for A=1,H do if x[A]==1 then x[A]=0 else x[A]=1 end end;return w(x)end;G=function(r)if r<0 then return G(i(math.abs(r))+1)end;local x={}local I=1;local J;while r>0 do J=r%2;x[I]=J;r=(r-J)/2;I=I+1 end;return x end;g=function(K,r)local L=G(K)local M=G(r)B(L,M)local x={}for A=1,#L do if L[A]==0 and M[A]==0 then x[A]=0 else x[A]=1 end end;return w(x)end;h=function(K,r)local L=G(K)local M=G(r)B(L,M)local x={}for A=1,#L do if L[A]==0 or M[A]==0 then x[A]=0 else x[A]=1 end end;return w(x)end;j=function(K,r)local L=G(K)local M=G(r)B(L,M)local x={}for A=1,#L do if L[A]~=M[A]then x[A]=1 else x[A]=0 end end;return w(x)end;k=function(r,N)local O=0;if r<0 then r=i(math.abs(r))+1;O=0x80000000 end;local P=math.floor;for A=1,N do r=r/2;r=g(P(r),O)end;return P(r)end;l=function(r,N)if r<0 then r=i(math.abs(r))+1 end;for A=1,N do r=r*2 end;return h(r,0xFFFFFFFF)end end end;local Q;if o then local R=p.typeof("int[1]")Q=function(A)return p.string(R(A),4)end else Q=function(A)local t=function(S)return b(h(k(A,S),255))end;return t(0)..t(8)..t(16)..t(24)end end;local function T(S)local U=0;for A=1,#S do U=U*256+c(S,A)end;return U end;local V;if o then local W=p.typeof("const char*")local X=p.typeof("const int*")V=function(S)local Y=W(S)return p.cast(X,Y)[0]end else V=function(S)local U=0;for A=#S,1,-1 do U=U*256+c(S,A)end;return U end end;local function Z(S)return{V(f(S,1,4)),V(f(S,5,8)),V(f(S,9,12)),V(f(S,13,16)),V(f(S,17,20)),V(f(S,21,24)),V(f(S,25,28)),V(f(S,29,32)),V(f(S,33,36)),V(f(S,37,40)),V(f(S,41,44)),V(f(S,45,48)),V(f(S,49,52)),V(f(S,53,56)),V(f(S,57,60)),V(f(S,61,64))}end;local _={0xd76aa478,0xe8c7b756,0x242070db,0xc1bdceee,0xf57c0faf,0x4787c62a,0xa8304613,0xfd469501,0x698098d8,0x8b44f7af,0xffff5bb1,0x895cd7be,0x6b901122,0xfd987193,0xa679438e,0x49b40821,0xf61e2562,0xc040b340,0x265e5a51,0xe9b6c7aa,0xd62f105d,0x02441453,0xd8a1e681,0xe7d3fbc8,0x21e1cde6,0xc33707d6,0xf4d50d87,0x455a14ed,0xa9e3e905,0xfcefa3f8,0x676f02d9,0x8d2a4c8a,0xfffa3942,0x8771f681,0x6d9d6122,0xfde5380c,0xa4beea44,0x4bdecfa9,0xf6bb4b60,0xbebfbc70,0x289b7ec6,0xeaa127fa,0xd4ef3085,0x04881d05,0xd9d4d039,0xe6db99e5,0x1fa27cf8,0xc4ac5665,0xf4292244,0x432aff97,0xab9423a7,0xfc93a039,0x655b59c3,0x8f0ccc92,0xffeff47d,0x85845dd1,0x6fa87e4f,0xfe2ce6e0,0xa3014314,0x4e0811a1,0xf7537e82,0xbd3af235,0x2ad7d2bb,0xeb86d391,0x67452301,0xefcdab89,0x98badcfe,0x10325476}local t=function(a0,a1,a2)return g(h(a0,a1),h(-a0-1,a2))end;local a3=function(a0,a1,a2)return g(h(a0,a2),h(a1,-a2-1))end;local a4=function(a0,a1,a2)return j(a0,j(a1,a2))end;local A=function(a0,a1,a2)return j(a1,g(a0,-a2-1))end;local a2=function(a5,u,v,a6,a7,a0,S,a8)u=h(u+a5(v,a6,a7)+a0+a8,0xFFFFFFFF)return g(l(h(u,k(0xFFFFFFFF,S)),S),k(u,32-S))+v end;local function a9(aa,ab,ac,ad,ae)local u,v,a6,a7=aa,ab,ac,ad;local af=_;u=a2(t,u,v,a6,a7,ae[0],7,af[1])a7=a2(t,a7,u,v,a6,ae[1],12,af[2])a6=a2(t,a6,a7,u,v,ae[2],17,af[3])v=a2(t,v,a6,a7,u,ae[3],22,af[4])u=a2(t,u,v,a6,a7,ae[4],7,af[5])a7=a2(t,a7,u,v,a6,ae[5],12,af[6])a6=a2(t,a6,a7,u,v,ae[6],17,af[7])v=a2(t,v,a6,a7,u,ae[7],22,af[8])u=a2(t,u,v,a6,a7,ae[8],7,af[9])a7=a2(t,a7,u,v,a6,ae[9],12,af[10])a6=a2(t,a6,a7,u,v,ae[10],17,af[11])v=a2(t,v,a6,a7,u,ae[11],22,af[12])u=a2(t,u,v,a6,a7,ae[12],7,af[13])a7=a2(t,a7,u,v,a6,ae[13],12,af[14])a6=a2(t,a6,a7,u,v,ae[14],17,af[15])v=a2(t,v,a6,a7,u,ae[15],22,af[16])u=a2(a3,u,v,a6,a7,ae[1],5,af[17])a7=a2(a3,a7,u,v,a6,ae[6],9,af[18])a6=a2(a3,a6,a7,u,v,ae[11],14,af[19])v=a2(a3,v,a6,a7,u,ae[0],20,af[20])u=a2(a3,u,v,a6,a7,ae[5],5,af[21])a7=a2(a3,a7,u,v,a6,ae[10],9,af[22])a6=a2(a3,a6,a7,u,v,ae[15],14,af[23])v=a2(a3,v,a6,a7,u,ae[4],20,af[24])u=a2(a3,u,v,a6,a7,ae[9],5,af[25])a7=a2(a3,a7,u,v,a6,ae[14],9,af[26])a6=a2(a3,a6,a7,u,v,ae[3],14,af[27])v=a2(a3,v,a6,a7,u,ae[8],20,af[28])u=a2(a3,u,v,a6,a7,ae[13],5,af[29])a7=a2(a3,a7,u,v,a6,ae[2],9,af[30])a6=a2(a3,a6,a7,u,v,ae[7],14,af[31])v=a2(a3,v,a6,a7,u,ae[12],20,af[32])u=a2(a4,u,v,a6,a7,ae[5],4,af[33])a7=a2(a4,a7,u,v,a6,ae[8],11,af[34])a6=a2(a4,a6,a7,u,v,ae[11],16,af[35])v=a2(a4,v,a6,a7,u,ae[14],23,af[36])u=a2(a4,u,v,a6,a7,ae[1],4,af[37])a7=a2(a4,a7,u,v,a6,ae[4],11,af[38])a6=a2(a4,a6,a7,u,v,ae[7],16,af[39])v=a2(a4,v,a6,a7,u,ae[10],23,af[40])u=a2(a4,u,v,a6,a7,ae[13],4,af[41])a7=a2(a4,a7,u,v,a6,ae[0],11,af[42])a6=a2(a4,a6,a7,u,v,ae[3],16,af[43])v=a2(a4,v,a6,a7,u,ae[6],23,af[44])u=a2(a4,u,v,a6,a7,ae[9],4,af[45])a7=a2(a4,a7,u,v,a6,ae[12],11,af[46])a6=a2(a4,a6,a7,u,v,ae[15],16,af[47])v=a2(a4,v,a6,a7,u,ae[2],23,af[48])u=a2(A,u,v,a6,a7,ae[0],6,af[49])a7=a2(A,a7,u,v,a6,ae[7],10,af[50])a6=a2(A,a6,a7,u,v,ae[14],15,af[51])v=a2(A,v,a6,a7,u,ae[5],21,af[52])u=a2(A,u,v,a6,a7,ae[12],6,af[53])a7=a2(A,a7,u,v,a6,ae[3],10,af[54])a6=a2(A,a6,a7,u,v,ae[10],15,af[55])v=a2(A,v,a6,a7,u,ae[1],21,af[56])u=a2(A,u,v,a6,a7,ae[8],6,af[57])a7=a2(A,a7,u,v,a6,ae[15],10,af[58])a6=a2(A,a6,a7,u,v,ae[6],15,af[59])v=a2(A,v,a6,a7,u,ae[13],21,af[60])u=a2(A,u,v,a6,a7,ae[4],6,af[61])a7=a2(A,a7,u,v,a6,ae[11],10,af[62])a6=a2(A,a6,a7,u,v,ae[2],15,af[63])v=a2(A,v,a6,a7,u,ae[9],21,af[64])return h(aa+u,0xFFFFFFFF),h(ab+v,0xFFFFFFFF),h(ac+a6,0xFFFFFFFF),h(ad+a7,0xFFFFFFFF)end;local function ag(self,S)self.pos=self.pos+#S;S=self.buf..S;for ah=1,#S-63,64 do local ae=Z(f(S,ah,ah+63))assert(#ae==16)ae[0]=table.remove(ae,1)self.a,self.b,self.c,self.d=a9(self.a,self.b,self.c,self.d,ae)end;self.buf=f(S,math.floor(#S/64)*64+1,#S)return self end;local function ai(self)local aj=self.pos;local ak=56-aj%64;if aj%64>56 then ak=ak+64 end;if ak==0 then ak=64 end;local S=b(128)..e(b(0),ak-1)..Q(h(8*aj,0xFFFFFFFF))..Q(math.floor(aj/0x20000000))ag(self,S)assert(self.pos%64==0)return Q(self.a)..Q(self.b)..Q(self.c)..Q(self.d)end;function a.new()return{a=_[65],b=_[66],c=_[67],d=_[68],pos=0,buf='',update=ag,finish=ai}end;function a.tohex(S)return d("%08x%08x%08x%08x",T(f(S,1,4)),T(f(S,5,8)),T(f(S,9,12)),T(f(S,13,16)))end;function a.sum(S)return a.new():update(S):finish()end;function a.sumhexa(S)return a.tohex(a.sum(S))end;return a