admin 管理员组

文章数量: 887021

import base64
import win32api
from pyDes import *
from pyDes import des,PAD_PKCS5,ECB

# #from binascii import a2b_hex #如果需要用二进制编码保存注册码和注册文件可以使用binascii转换
# class register:
#     def __init__(self):
#         self.Des_Key = "BHC#@*UM" # Key
#         self.Des_IV = "\x22\x33\x35\x81\xBC\x38\x5A\xE7" # 自定IV向量
#     #获取C盘卷序列号
#     #使用C盘卷序列号的优点是长度短,方便操作,比如1513085707,但是对C盘进行格式化或重装电脑等操作会影响C盘卷序列号。
#     #win32api.GetVolumeInformation(Volume Name, Volume Serial Number, Maximum Component Length of a file name, Sys Flags, File System Name)
#     #return('', 1513085707, 255, 65470719, 'NTFS'),volume serial number is 1513085707.
#     def getCVolumeSerialNumber(self):
#         CVolumeSerialNumber=win32api.GetVolumeInformation("C:\\")[1]
#         if CVolumeSerialNumber:
#             return str(CVolumeSerialNumber) #number is long type,has to be changed to str for comparing to content after.
#         else:
#             return 0
def write_str(data):
    f = open("C:/a.txt", 'w')
    f.write(data)
    f.close()

def read_str():
    f = open("C:/a.txt",encoding='utf-8')
    line = f.readline()
    f.close()
    return line

#获取本机注册号
def get_registration_Number():
    CVolumeSerialNumber=win32api.GetVolumeInformation("C:\\")[1]
    if CVolumeSerialNumber:
        return str(CVolumeSerialNumber) #number is long type,has to be changed to str for comparing to content after.
    else:
        return 0

#根据注册号生成
def create_key(DES_SECRET,data):
    desObj = des(DES_SECRET,ECB,None,padmode=PAD_PKCS5)
    #加密
    myencrypt_jia = desObj.encrypt(data)
    a=base64.b64encode(myencrypt_jia)  #转base64编码返回
    return a.decode().strip()

#校验
def vs(DES_SECRET,data,key):
    key=base64.b64decode(key)  #base64解码返回
    #解密
    desObj = des(DES_SECRET,ECB,None,padmode=PAD_PKCS5)
    mydecrypt_jie = desObj.decrypt(key)
    bb=mydecrypt_jie.decode()
    if data==bb:
        print("ok!!")


if __name__ == '__main__':
#     showUI()
    # data=get_registration_Number()
    # print(data)
    # #设置加密时添加的秘钥
    # DES_SECRET = 'salman12'
    
    # desObj = des(DES_SECRET,ECB,None,padmode=PAD_PKCS5)
    # #加密
    # myencrypt_jia = desObj.encrypt(data)
    # #解密
    # mydecrypt_jie = desObj.decrypt(myencrypt_jia)

    # a=base64.b64encode(myencrypt_jia)  #转base64编码返回
    # print(a)
    # b=a.decode().strip()  #去除b字符
    # print(b)



    # print(mydecrypt_jie.decode())
    a=get_registration_Number()   #获取本机注册号
     #设置加密时添加的秘钥
    DES_SECRET = 'salman12'    #设置密钥
    b=create_key(DES_SECRET,a)    #根据注册号生成激活码
    write_str(b)
    read_read=read_str()
    print("read:"+read_read)
    print(a)
    print(b)
    vs(DES_SECRET,a,b)   

本文标签: 激活码 软件 python