编辑代码

## Python代码
import hashlib
import random

def m4(string_7):
    text2 = ""
    text3 = ""
    text2 += string_7[10:12] + string_7[0:2] + string_7[14:16]
    text2 += string_7[21:23] + string_7[6:8] + string_7[4:6]
    print(text2)
    for num in range(1,13):
        charAtIndex = text2[num-1]
        if charAtIndex.isdigit():
            numValue = int(charAtIndex)
            text3 += str(numValue ^ 5)
        else:
            text4 = chr(ord(charAtIndex) + 20 - num)
            if text4 == "O":
                text3 += "0"
            else:
                text3 += text4
    text3 = text3.replace("0", "7")
    # 重新排列 text3
    result = text3[8:10] + text3[4:6] + text3[10:12] + text3[6:8]
    return result

def m12(string_7):
    length = len(string_7)
    num = 0
    if length > 0:
        for i in range(length):
            num3 = ord(string_7[i])
            num4 = num3 + 7
            num5 = num3 * 5
            num += smethod_8(num3, num4, num5)
            num += smethod_9(num3, num4, num5)
            num += smethod_10(num3, num4, num5)
            num *= smethod_11(num3, num4, num5) + 12
            if num > 100000000:
                num = int(str(num)[max(0,len(str(num))-7):])
        text = str(num)
        if len(text) >= 6:
            return text[len(text)-6:]
        else:
            return str(num + 523109)[max(0, len(str(num+523109))-6):]
    else:
        return ""

def smethod_8(int_0, int_1, int_2):
    return (int_0 << 2) | (int_1 & int_2)

def smethod_9(int_0, int_1, int_2):
    return int_0 & int_2 & ((int_1 << 3) | int_2)
   
def smethod_10(int_0, int_1, int_2):
    return (int_0 & (int_2 << 2)) | ((int_1 << 3) & int_2)

def smethod_11(int_0, int_1, int_2):
    return (int_0 << 4) & (int_2 << 2) & ((int_1 << 2) | int_2)

def string_to_md5(string):
    return hashlib.md5(string.encode('utf8')).hexdigest().upper()


def main(pcCode, regDate="20291228"):
    text = pcCode.replace("-", "")
    if len(text) > 10:
        text = text[0:10] + text[len(text)-5:]
    regCode = m4(string_to_md5(m12(text)))
   
    # 年份yyyy 后2位对应注册码 5-6位
    # 6,7,B=>1 对应1几年 8,9,C=>2 对应2几年
    year3 = ["8", "9", "C"]
    # 年份第四位对照关系
    year41 = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
    year42 = ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K"]
    # 月份MM 对应注册码7-8位
    # 月份第一位, 6,7,B=>1 对应1 4,5,A=>0 对应0 月份第二位对照关系同年份第四位对照关系
    month10 = ["4", "5", "A"]
    month11 = ["6", "7", "B"]
    # 日dd对应注册码13,14位
    # 第一位A,B,C=> 0,1,2 第二位0-8不用对应直接用
    i = random.randint(0,2)
    # 注册码
    y3 = regDate[2]
    y4 = regDate[3]
    m1 = regDate[4]
    m2 = regDate[5]
    d1 = regDate[6]
    d2 = regDate[7]
    month = month10[:] if m1=="0" else month11[:]
    # 注册码拼接
    zccode = regCode[0:4]
    zccode += year3[i]
    zccode += year42[year41.index(y4)]
    zccode += month[i]
    zccode += year42[year41.index(m2)]
    zccode += regCode[4:8]
    zccode += year42[year41.index(d1)]
    zccode += d2 + "2"
    return zccode

if __name__ == "__main__":
    regDate = "20291228"
    while True:
        pcCode = input("输入机器码:")
        if not pcCode or pcCode.lower() in ["q","e","quit","exit"]:
            break
        print(f"   注册码:{main(pcCode)}")