import random

bw = "phuykgnkhyp"  # 补位字母
# 数字转换字典
zero = "qw"
one = "rs"
two = "zx"
three = "[-"
four = "~]"
five = "()"
six = "!{"
seven = "@$"
eight = "}*"
nine = "^:"

def get_sjbw(length):
    res = ""
    for i in range(1, length+1):
        res += random.choice(bw)
    return res

# 解密补位字符替换为‘ ’
def get_jmreplace(keystr):
    for i in bw:
        keystr = keystr.replace(i, ' ')
    return keystr

def get_en_numchange(number):
    return number[random.randint(0, len(number)-1)]

def get_en_allchange(keystr):
    # tjmv
    if keystr == "a":
        keystr = "f"
    elif keystr == "b":
        keystr = "t"
    elif keystr == "c":
        keystr = "j"
    elif keystr == "d":
        keystr = "m"
    elif keystr == "e":
        keystr = "v"
    elif keystr == "f":
        keystr = "b"
    elif keystr == "0":
        keystr = get_en_numchange(zero)
    elif keystr == "1":
        keystr = get_en_numchange(one)
    elif keystr == "2":
        keystr = get_en_numchange(two)
    elif keystr == "3":
        keystr = get_en_numchange(three)
    elif keystr == "4":
        keystr = get_en_numchange(four)
    elif keystr == "5":
        keystr = get_en_numchange(five)
    elif keystr == "6":
        keystr = get_en_numchange(six)
    elif keystr == "7":
        keystr = get_en_numchange(seven)
    elif keystr == "8":
        keystr = get_en_numchange(eight)
    elif keystr == "9":
        keystr = get_en_numchange(nine)
    return keystr

#解密字符转换
def get_de_allchange(keystr):
    if keystr == 'v':
        keystr = 'e'
    elif keystr == 'b':
        keystr = 'f'
    elif keystr == 'f':
        keystr = 'a'
    elif keystr == 't':
        keystr = 'b'
    elif keystr == 'j':
        keystr = 'c'
    elif keystr == 'm':
        keystr = 'd'
    else:
        if keystr in zero:
            keystr = '0'
        elif keystr in one:
            keystr = '1'
        elif keystr in two:
            keystr = '2'
        elif keystr in three:
            keystr = '3'
        elif keystr in four:
            keystr = '4'
        elif keystr in five:
            keystr = '5'
        elif keystr in six:
            keystr = '6'
        elif keystr in seven:
            keystr = '7'
        elif keystr in eight:
            keystr = '8'
        elif keystr in nine:
            keystr = '9'
        else:
            keystr = '*'
    return keystr

def decrypt_tj(strAnMa):
    strReturnInfo = ""
    strAMSub = ""
    strTotalAMInfo = ""
    strOne, strServer, strFour = "", "", ""
    strAnMa = get_jmreplace(strAnMa).strip()
    for i in strAnMa:
        strAMSub = get_de_allchange(str(i))
        strTotalAMInfo += strAMSub
    try:
        strTotalAMInfo = str(int(strTotalAMInfo, 16)).strip()
        if len(strTotalAMInfo) == 1:
            strTotalAMInfo = "00000000000" + strTotalAMInfo
        elif len(strTotalAMInfo) == 2:
            strTotalAMInfo = "0000000000" + strTotalAMInfo
        elif len(strTotalAMInfo) == 3:
            strTotalAMInfo = "000000000" + strTotalAMInfo
        elif len(strTotalAMInfo) == 4:
            strTotalAMInfo = "00000000" + strTotalAMInfo
        elif len(strTotalAMInfo) == 5:
            strTotalAMInfo = "0000000" + strTotalAMInfo
        elif len(strTotalAMInfo) == 6:
            strTotalAMInfo = "000000" + strTotalAMInfo
        elif len(strTotalAMInfo) == 7:
            strTotalAMInfo = "00000" + strTotalAMInfo
        elif len(strTotalAMInfo) == 8:
            strTotalAMInfo = "0000" + strTotalAMInfo
        elif len(strTotalAMInfo) == 9:
            strTotalAMInfo = "000" + strTotalAMInfo
        elif len(strTotalAMInfo) == 10:
            strTotalAMInfo = "00" + strTotalAMInfo
        elif len(strTotalAMInfo) == 11:
            strTotalAMInfo = "0" + strTotalAMInfo
        strReturnInfo = strTotalAMInfo
        strOne = strReturnInfo[0].strip()
        strServer = strReturnInfo[1:8].strip()
        strFour = strReturnInfo[8:12].strip()
        strReturnInfo = strFour + strServer + strOne
        return strReturnInfo
    except Exception as ex:
        return "no"