encode chinese name
This commit is contained in:
+43
-14
@@ -1,20 +1,49 @@
|
||||
import re
|
||||
|
||||
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"
|
||||
last_name = "PAN"
|
||||
passport_number = "G22611379"
|
||||
birth_day = "841215"
|
||||
sex = "M"
|
||||
optinal_data = "19203301<<<<<<" #14位
|
||||
expire_date = "170510"
|
||||
def encode(s: str) -> list[str]:
|
||||
s = s.encode(encoding='gb2312').hex()
|
||||
res = []
|
||||
for c in s:
|
||||
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 = "王瑾欣"
|
||||
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,
|
||||
optinal_data)
|
||||
|
||||
Reference in New Issue
Block a user