Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Bit Message by Somebody12345678910
from io import StringIO
mnames = dict(list(zip(list(range(1,13)),
('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'))))
def checkio(data):
msg = StringIO(data);msgtype = int(msg.read(2));is8bit = bool(msgtype & 4);is16bit = bool(msgtype & 8);is7bit = not is8bit and not is16bit;tstamp = msg.read(12)[::-1];S, M, H, d, m, y = (tstamp[i:i+2] for i in range(0, 12, 2));y = '19%s' % y if int(y) > 69 else '20%s' % y;tz1 = int(msg.read(1), 16);tz2 = int(msg.read(1), 16)
if tz2 & 8:tz2 &= 7;sign = -1
else:sign = 1
tz = sign * (tz1 + tz2 * 10) * 15 / 60; tstamp = '%02s %s %02s %02s:%02s:%02s GMT %+d' % (d, mnames[int(m)], y,H, M, S, tz);length = int(msg.read(2), 16);buf = StringIO();save = octs_read = 0
while buf.tell() < length:
if is16bit:cp = int(msg.read(4), 16)
else:cp = int(msg.read(2), 16)
if is7bit:k = octs_read % 7;save_ = cp >> 7 - k;cp = ((cp & (2 ** (7 - k) - 1)) << k) + save;octs_read += 1;save = save_
buf.write(chr(cp))
if is7bit and k == 6 and buf.tell() < length:buf.write(chr(save));save = 0
decoded_msg = buf.getvalue();buf.close();return [tstamp, length, decoded_msg]
July 17, 2021