Skip to content

Instantly share code, notes, and snippets.

@li0ard
Created May 18, 2022 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save li0ard/150558243859ad1d137ceda0489b9303 to your computer and use it in GitHub Desktop.
Save li0ard/150558243859ad1d137ceda0489b9303 to your computer and use it in GitHub Desktop.
Примерный скрипт для получения текстовых данных с штрихкода УЛМ
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:]))
@li0ard
Copy link
Author

li0ard commented May 18, 2022

Запуск: python3 ulm_decoder.py ulm.bin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment