create mrzutil for cards

This commit is contained in:
2023-02-05 12:21:41 +01:00
parent 83d37f2ced
commit c08ccd1d22
2 changed files with 16 additions and 38 deletions
+7 -6
View File
@@ -22,16 +22,17 @@ def decode(s: str) -> list[str]:
return bytes(res).decode('gb2312') return bytes(res).decode('gb2312')
chinese_name = "王雅芳" chinese_name = "陈锦凡"
encoded_chinese_name = encode(chinese_name) encoded_chinese_name = encode(chinese_name)
print(encoded_chinese_name) print(encoded_chinese_name)
optional_data_length = 14 - len(encoded_chinese_name) optional_data_length = 14 - len(encoded_chinese_name)
for i in range(0, optional_data_length): for i in range(0, optional_data_length):
encoded_chinese_name = encoded_chinese_name + "<" encoded_chinese_name = encoded_chinese_name + "<"
first_name = "yafang" first_name = "Jingfan"
last_name = "WANG" last_name = "CHEN"
passport_number = "E09715300" passport_number = "E55757396"
birth_day = "991215" birth_day = "980118"
# sex = "F"
sex = "M" sex = "M"
# optinal_data = "MFMLMANK<<<<A9" #14位 # optinal_data = "MFMLMANK<<<<A9" #14位
# nationality = "CHN" # nationality = "CHN"
@@ -44,7 +45,7 @@ else:
optinal_data = encoded_chinese_name # 14位 optinal_data = encoded_chinese_name # 14位
document_prefix = "PO" document_prefix = "PO"
expire_date = "290116" expire_date = "270116"
# first_name = "Lei" # first_name = "Lei"
# last_name = "PAN" # last_name = "PAN"
+9 -32
View File
@@ -3,41 +3,18 @@ import re
from mrz.generator.td1 import TD1CodeGenerator from mrz.generator.td1 import TD1CodeGenerator
def encode(s: str) -> list[str]: first_name = "minqin"
s = s.encode(encoding='gb2312').hex() last_name = "YANG"
res = [] document_number = "XKJ0WSK30"
for c in s: birth_day = "980829"
res.append(chr(ord('a') + int(c, base=16)))
return "".join(res).upper()
def decode(s: str) -> list[str]:
t = []
for c in s:
t.append(format((ord(c) - ord('A')), 'x'))
t = re.findall('.{1,2}', "".join(t))
res = []
for c in t:
res.append(int("0x" + c, 16))
return bytes(res).decode('gb2312')
chinese_name = "黄慧逸"
# optional_data_length = 14 - len(encoded_chinese_name)
# for i in range(0, optional_data_length):
# encoded_chinese_name = encoded_chinese_name + "<"
first_name = "Huiyi"
last_name = "HUANG"
passport_number = "E82647589"
birth_day = "980120"
sex = "F" sex = "F"
# optinal_data = "MFMLMANK<<<<A9" #14位 # optinal_data = "MFMLMANK<<<<A9" #14位
nationality = "CHN" nationality = "CHN"
country_code = "HUN" country_code = "FRA"
# optinal_data = "799283" # 14位 optinal_data = "<9918136584" # 14位
document_prefix = "IR" document_prefix = "IR"
expire_date = "250922" expire_date = "230815"
# first_name = "Lei" # first_name = "Lei"
# last_name = "PAN" # last_name = "PAN"
@@ -47,8 +24,8 @@ expire_date = "250922"
# optinal_data = "19203301<<<<<<" #14位 # optinal_data = "19203301<<<<<<" #14位
# expire_date = "170510" # expire_date = "170510"
code = TD1CodeGenerator(document_prefix, country_code, passport_number, birth_day, sex, expire_date, nationality, code = TD1CodeGenerator(document_prefix, country_code, document_number, birth_day, sex, expire_date, nationality,
last_name, first_name) last_name, first_name, optional_data1=optinal_data)
# code = TD3CodeGenerator("PO", "CHN", "PAN", "LEI", "E90600575", "CHN", "841215", "M", "270116", "MFMLMANK<<<<A9") # code = TD3CodeGenerator("PO", "CHN", "PAN", "LEI", "E90600575", "CHN", "841215", "M", "270116", "MFMLMANK<<<<A9")
print(code) print(code)