From 04c3da59620c9cf3d826f209bcb4b55b255517b5 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 4 Aug 2022 00:56:29 +0100 Subject: chat monitor ification --- md5.lua | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 md5.lua (limited to 'md5.lua') diff --git a/md5.lua b/md5.lua new file mode 100644 index 0000000..b421587 --- /dev/null +++ b/md5.lua @@ -0,0 +1,167 @@ +-- from https://github.com/philanc/plc/blob/master/plc/md5.lua +------------------------------------------------------------------------ +-- md5 hash - see RFC 1321 - https://www.ietf.org/rfc/rfc1321.txt + +local spack, sunpack = string.pack, string.unpack + +------------------------------------------------------------------------ + +local function FF(a, b, c, d, x, s, ac) + a = (a + ((b & c) | ((~b) & d)) + x + ac) & 0xffffffff + a = ((a << s) | (a >> (32-s))) & 0xffffffff + a = (a + b) & 0xffffffff + return a +end + +local function GG(a, b, c, d, x, s, ac) + a = (a + ((b & d) | c & (~d) ) + x + ac) & 0xffffffff + a = ((a << s) | (a >> (32-s))) & 0xffffffff + a = (a + b) & 0xffffffff + return a +end + +local function HH(a, b, c, d, x, s, ac) + a = (a + ((b ~ c ~ d)) + x + ac) & 0xffffffff + a = ((a << s) | (a >> (32-s))) & 0xffffffff + a = (a + b) & 0xffffffff + return a +end + +local function II(a, b, c, d, x, s, ac) + a = (a + (c ~ (b | ~d)) + x + ac) & 0xffffffff + a = ((a << s) | (a >> (32-s))) & 0xffffffff + a = (a + b) & 0xffffffff + return a +end + +local function transform(state, input, i, t) + -- process the 64-byte input block in string 'input' at offset 'i' + -- t is a uint32[16] array. It is passed as a parameter + -- for performance reasons + -- + local a, b, c, d = state[1], state[2], state[3], state[4] + + -- load array + for j = 1, 16 do + t[j] = sunpack("= 64 do + -- process block + transform(state, input, i, ibt) + i = i + 64 -- update input index + r = r - 64 -- update number of unprocessed bytes + end + -- finalize. must append to input a mandatory 0x80 byte, some + -- padding, and the input bit-length ('inputbits') + local lastblock -- the rest of input .. some padding .. inputbits + local padlen -- padding length in bytes + if r < 56 then padlen = 55 - r else padlen = 119 - r end + lastblock = input:sub(i) -- remaining input + .. '\x80' .. ('\0'):rep(padlen) --padding + .. spack("