Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lrr_wiegand_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#############################################################################

import pigpio
from Crypto.Cipher import DES3
from binascii import hexlify

iclass_key = "00000000000000000000000000000000"

# The magic code to decode wiegand data from the wiegand data lines. Borrowed from http://abyz.co.uk/rpi/pigpio/examples.html
class decoder:
Expand Down Expand Up @@ -123,6 +127,14 @@ def validateCSV(file):
if not (id_num.isdigit()):
id_num = 0

def encryptIClass(wiegand_hex):
if iclass_key == "00000000000000000000000000000000":
return "FFFFFFFFFFFFFFFF".upper()
else:
key = iclass_key.decode("hex")
cipher = DES3.new(key, DES3.MODE_ECB)
plaintext = wiegand_hex.decode("hex")
return hexlify(cipher.encrypt(plaintext)).upper()

# Add scanned cards to CSV file
def addCardsToCSV(bits, wiegand_binary, wiegand_hex, enc_hex, fac_code, card_num, card_num_no_fac):
Expand Down Expand Up @@ -170,7 +182,7 @@ def callback(bits, value):
fac_code, card_num, card_num_no_fac, hidHeader = decodeWiegandData(bits, wiegand_binary)
wiegand_binary = hidHeader + wiegand_binary
wiegand_hex = "%016X" % int(wiegand_binary, 2)
enc_hex = "FFFFFFFFFFFFFFFF".upper() # To Implement
enc_hex = encryptIClass(wiegand_hex)
addCardsToCSV(bits, wiegand_binary, wiegand_hex, enc_hex, fac_code, card_num, card_num_no_fac)

# Debug output to console
Expand All @@ -195,4 +207,4 @@ def callback(bits, value):
raw_input()
w.cancel()
pi.stop()