Created
May 18, 2022 13:56
-
-
Save li0ard/150558243859ad1d137ceda0489b9303 to your computer and use it in GitHub Desktop.
Примерный скрипт для получения текстовых данных с штрихкода УЛМ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
import ctypes, sys | |
def binfile2hexstr(filename): | |
buff = [] | |
with open(filename, 'rb') as in_file: | |
while True: | |
hexdata = in_file.read(16).hex() | |
if len(hexdata) == 0: | |
break | |
buff.append(hexdata.upper()) | |
return "".join(buff) | |
def hex2ascii(hex): | |
return bytes.fromhex(hex).decode('utf-8') | |
def s32(val): | |
return ctypes.c_int32(eval("0x" + val)).value | |
code = binfile2hexstr(sys.argv[1]) | |
code = code.split("0283") | |
code.pop(0) | |
code = "0283".join(code) | |
print("Фамилия: " + hex2ascii(code[54:94])) | |
print("Имя: " + hex2ascii(code[94:134])) | |
print("Дата рождения: " + datetime.fromtimestamp(s32(code[178:186])).strftime("%d.%m.%Y")) | |
print("Место рождения: " + hex2ascii(code[138:178])) | |
if code[186:188] == "6D": | |
print("Пол: M") | |
else: | |
print("Пол: Ж") | |
print("№ Документа: " + hex2ascii(code[:18])) | |
print("Дата выдачи: " + datetime.fromtimestamp(int(code[188:196], 16)).strftime("%d.%m.%Y")) | |
print("Дата окончания: " + datetime.fromtimestamp(int(code[46:54], 16)).strftime("%d.%m.%Y")) | |
print("Место выдачи: " + hex2ascii(code[196:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Запуск:
python3 ulm_decoder.py ulm.bin