-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbarcode_encryptor.py
36 lines (29 loc) · 1.3 KB
/
barcode_encryptor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import base64
# Expected field names (adjust according to your barcode structure)
FIELD_NAMES = [
"Surname", "Given Name", "Other Names", "Date of Birth",
"Issue Date", "Expiry Date", "NIN", "Card Number", "Additional Data"
]
def decode_barcode_data(barcode_data):
"""
Decodes a scanned PDF417 barcode and prints extracted data with labels.
"""
try:
# Split barcode data by semicolon
parts = barcode_data.split(';')
print("\n✅ Decoded Barcode Data:")
for index, part in enumerate(parts):
try:
decoded_value = base64.b64decode(part).decode("utf-8")
except (base64.binascii.Error, UnicodeDecodeError):
decoded_value = "Invalid Data" # Handle decoding errors
# Assign a field name if available, otherwise use "Unknown Field"
field_name = FIELD_NAMES[index] if index < len(FIELD_NAMES) else f"Unknown Field {index + 1}"
print(f"{field_name}: {decoded_value}")
except Exception as e:
print(f"❌ Error decoding barcode: {e}")
if __name__ == "__main__":
# Wait for input from the physical barcode scanner
scanned_data = input("\n📡 Please scan a PDF417 barcode: ")
# Decode and display the scanned barcode data
decode_barcode_data(scanned_data)