Skip to content

Instantly share code, notes, and snippets.

@0xquad
Last active August 29, 2015 14:04
Show Gist options
  • Save 0xquad/d58fb05733fe574effd3 to your computer and use it in GitHub Desktop.
Save 0xquad/d58fb05733fe574effd3 to your computer and use it in GitHub Desktop.
Simple Python class to interpret a raw bit stream as read from an EM410x RFID tag.
#!/usr/bin/env python3
class EM410x:
def __init__(self, bits):
assert len(bits) == 64
self.header = bits[:9]
self.nibbles = []
for i in range(9, 9 + 5 * 11, 5):
self.nibbles.append((bits[i:i+4], bits[i+4]))
def __str__(self):
site = ''.join(n[0] for n in self.nibbles[:2])
id = ''.join(n[0] for n in self.nibbles[2:-1])
unique_id = ''.join(n[0][::-1] for n in self.nibbles[0:-1])
return (
'<EM4100 header={hdr!r}'
' data={data!r}'
' (site={site:02x} id={id:08x} parity={par!r}, uniq={uniq:10x})>'.format(
hdr='0b' + self.header,
data=self.nibbles,
site=int(site, 2),
id=int(id, 2),
par=self.nibbles[-1],
uniq=int(unique_id, 2)
)
)
if __name__ == '__main__':
import sys
print(EM410x(sys.argv[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment