Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Bit Message by Tinus_Trotyl
def read_7(data, lng): # 7 bit format content reader
j, carry, bits = 0, 0, 0
message = [" " for _ in range(lng)]
for i in range(0, len(data), 2):
databyte = int(data[i: i+2], 16)
message[j] = chr(((databyte * (2 ** bits)) & 0x7F) + carry)
carry = (databyte * (2 ** bits)) // 0x80
j += 1
bits += 1
if bits == 7 and j < lng:
message[j] = chr(carry)
carry, bits = 0, 0
j += 1
return "".join(i for i in message)
def read_8(data): # 8 bit format content reader
return "".join(chr(int(data[i: i+2], 16)) for i in range(0, len(data), 2))
def read16(data): #16 bit format content reader
return "".join(chr(int(data[i: i+4], 16)) for i in range(0, len(data), 4))
### bit message decoder ###
def checkio(data):
head = [int(data[2*i+1] + data[2*i]) for i in range(1, 7)]
type = 16 if int(data[1]) & 8 else (8 if int(data[1]) & 4 else 7)
year = str((2000 if head[0] < 70 else 1900) + head[0])
month = ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][head[1]]
day = str(100 + head[2])[1:]
hours = str(100 + head[3])[1:]
mins = str(100 + head[4])[1:]
secs = str(100 + head[5])[1:]
zono = str((10 * (int(data[15], 16) & 0x07) + int(data[14])) // 4)
zone = ("-" if int(data[15], 16) & 0x08 and int(zono) else "+") + zono
stamp = " ".join([day, month, year, hours + ":" + mins + ":" + secs, "GMT", zone])
lng = int(data[16:18], 16)
data = data[18:].strip()
return [stamp, lng, eval({7 :"read_7(data, lng)", 8 :"read_8(data)", 16 :"read16(data)"}[type])]
Feb. 8, 2018