|
@@ -34,23 +34,26 @@ def chunks(in_bytes: bytes, take_n: int) -> bytes:
|
|
|
|
|
|
|
|
|
def extract_lsbs(data):
|
|
|
- logger.info("Extract LSBs.")
|
|
|
+ deduced_data = bytearray()
|
|
|
+ previous_byte = None
|
|
|
|
|
|
- buffer = []
|
|
|
+ for byte in data:
|
|
|
+ if byte != previous_byte:
|
|
|
+ deduced_data.append(byte)
|
|
|
+ previous_byte = byte
|
|
|
|
|
|
- data = [k for k, _ in groupby(data)]
|
|
|
- data = bytes(data)
|
|
|
- data = chunks(data, 8)
|
|
|
+ buffer = bytearray()
|
|
|
+ chunk_size = 8
|
|
|
+ num_full_chunks = len(deduced_data) // chunk_size
|
|
|
|
|
|
- for chunk in data:
|
|
|
- if len(chunk) != 8:
|
|
|
- break
|
|
|
+ for i in range(num_full_chunks):
|
|
|
+ result_byte = 0
|
|
|
+ start_index = i * chunk_size
|
|
|
|
|
|
- ba = bitstring.BitArray(8)
|
|
|
- for i, byte in zip(range(len(chunk)), chunk):
|
|
|
- ba[i] = byte & 1
|
|
|
+ for j in range(chunk_size):
|
|
|
+ result_byte |= ((deduced_data[start_index + j] & 1) << (7 - j))
|
|
|
|
|
|
- buffer.append(ba.u)
|
|
|
+ buffer.append(result_byte)
|
|
|
|
|
|
return bytes(buffer)
|
|
|
|
|
@@ -131,5 +134,5 @@ class FrameTakeWorker:
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
- ftw = FrameTakeWorker(1)
|
|
|
+ ftw = FrameTakeWorker(0, 3)
|
|
|
asyncio.run(ftw.run_workers())
|