58 city font encryption and decryption method

Reference 4 basic packages

import re
from io import BytesIO
from fontTools.ttLib import TTFont
import base64

Use regular to extract the following content, this is an encrypted font base64 font file

The selected area is base64 font
Press F12 can view details
Insert picture description here

#code_str 为第一图蓝色字符串
def deciphering(ziti,code_str):
    result = []
    code_ziti = []
    font = TTFont(BytesIO(base64.decodebytes(code_str.encode())))
    c = font['cmap'].tables[0].ttFont.tables['cmap'].tables[0].cmap

    for i in range(len(ziti)):        
        #找出每一个字对应的16进制编码 逐一和字体文件做判断
        str_code =ziti[i].encode("unicode-escape").decode()[-4:]

		# \xa0 是空格
        if(str_code =='\\xa0'):
            str_code = ' '

		# 如果标点符号,转化后还是标点符号 长度为1
		# 如果包含则转换 
        if(len(str_code)>1):
            code = int(str_code,16)
            if(code in c):
                x = int(c[code][-2:])-1
                result.append(x)
            else:
                result.append(ziti[i])
        else:
            result.append(ziti[i])

	#  最后将数组转为字符串
    return "".join(map(lambda x:str(x),result))

Guess you like

Origin blog.csdn.net/lows_H/article/details/101421658