encode chinese name

This commit is contained in:
2023-01-14 00:27:28 +01:00
parent fde2b4564e
commit 135c638ee3
+43 -14
View File
@@ -1,20 +1,49 @@
import re
from mrz.generator.td3 import TD3CodeGenerator from mrz.generator.td3 import TD3CodeGenerator
# first_name = "JINXIN"
# last_name = "WANG"
# passport_number = "E59248934"
# birth_day = "941215"
# sex = "F"
# optinal_data = "MFMLMANK<<<<A9" #14位
# expire_date = "270116"
first_name = "Lei" def encode(s: str) -> list[str]:
last_name = "PAN" s = s.encode(encoding='gb2312').hex()
passport_number = "G22611379" res = []
birth_day = "841215" for c in s:
sex = "M" res.append(chr(ord('a') + int(c, base=16)))
optinal_data = "19203301<<<<<<" #14位 return "".join(res).upper()
expire_date = "170510"
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 = "王瑾欣"
encoded_chinese_name = encode(chinese_name)
print(encoded_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 = "JINXIN"
last_name = "WANG"
passport_number = "E59248934"
birth_day = "941215"
sex = "F"
# optinal_data = "MFMLMANK<<<<A9" #14位
optinal_data = encoded_chinese_name # 14位
expire_date = "270116"
# first_name = "Lei"
# last_name = "PAN"
# passport_number = "G22611379"
# birth_day = "841215"
# sex = "M"
# optinal_data = "19203301<<<<<<" #14位
# expire_date = "170510"
code = TD3CodeGenerator("PO", "CHN", last_name, first_name, passport_number, "CHN", birth_day, sex, expire_date, code = TD3CodeGenerator("PO", "CHN", last_name, first_name, passport_number, "CHN", birth_day, sex, expire_date,
optinal_data) optinal_data)