From 04c3da59620c9cf3d826f209bcb4b55b255517b5 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 4 Aug 2022 00:56:29 +0100 Subject: chat monitor ification --- chat.dat | 1 + chat.lua | 19 ++++++++ md5.lua | 167 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 187 insertions(+) create mode 100644 chat.dat create mode 100644 chat.lua create mode 100644 md5.lua diff --git a/chat.dat b/chat.dat new file mode 100644 index 0000000..5086928 --- /dev/null +++ b/chat.dat @@ -0,0 +1 @@ +dep md5 diff --git a/chat.lua b/chat.lua new file mode 100644 index 0000000..e21da68 --- /dev/null +++ b/chat.lua @@ -0,0 +1,19 @@ +local md5 = require("md5").hash + +local p = peripheral.find"manipulator" +assert(p and p.hasModule"plethora:chat") +local m = peripheral.wrap"monitor" +assert(m) + +local function p(...) + term.redirect(m) + print(...) + term.redirect(term.native()) +end + +while true do + local _,user,msg = os.pullEvent"chat_message" + local h = md5(msg) + + p("<"..user.."> ["..h.."] "..msg) +end 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("