Search code examples
pythontextencodingcompressionrfid

How to compress unique ID of object into 96 bit memory of RFID


RFID Technology in some countries is expensive and restriction is to have data stored in 96 bit memory tag. The system that I am using has 24 character code that conforms to type of packaging/contents and since its 128 bits it is expensive from memory standpoint.

Therefore, I would like to write a program in Python so that I can compress the same 24 code to 96 bits. If any other software like C can help please let me know. I should also have the capability to read it back and re-transform it.

A sample identification code is M1P100000812341567678991

Code

import zlib
import bz2
a = 'M1P100000812341567678991'
b = a.encode()
c = zlib.compress(b, level=9)

Thank You.


Solution

  • If you have 96 bits, that is 12 bytes. If the first three characters of your ID are alphabetic, then they will fit into the first three bytes. The rest, if taken as a binary number, should fit into 9 bytes:

    a = 'M1P990000812341567678991'
    head = a[:3]
    tail = a[3:]
    head = head.encode('utf-8')
    tail = int(tail).to_bytes(9, byteorder='little')
    print(head.hex())
    print(tail.hex())
    

    Output (in hex, but the two byte arrays are really 3 and 9 bytes in length)

    4d3150
    0fea4b57936d05ab35