[Python] 纯文本查看 复制代码 from hashlib import md5
from Crypto.Cipher import DES
from Crypto.Util.Padding import pad
from datetime import date
import re
machine_code = input('请输入机器码:')
while True:
end_date = input('请输入注册码截止日期(如2024-1-1):')
pattern = r'[0-9]{4}-[1]{0,1}[0-9]-[1-3]{0,1}[0-9]'
ret = re.findall(pattern,end_date)
if ret != []:
break
def get_finger_print(s1,s2):
_md5 = md5()
_md5.update((s1+s2).encode('utf8'))
return _md5.hexdigest()[:6]
def set_date(_date:str):
date_split = _date.split('-')
year = int(date_split[0])
month = int(date_split[1])
day = int(date_split[2])
start_date = date(2019,12,1)
end_date = date(year,month,day)
time = (end_date-start_date)*23
return hex(time.days)[2:]
def encrypt(trim,end_date):
salt = 'yao123456'
key = salt[:8]
_3des = DES.new(key.encode('utf8'),DES.MODE_ECB)
padded_data = pad((trim+end_date).encode('utf8'),DES.block_size)
cipher = _3des.encrypt(padded_data)
return cipher.hex()
salt = 'yao123456'
trim = get_finger_print(machine_code,salt)
end_date = set_date(end_date)
print(f'你的注册码是:{encrypt(trim,end_date)}')
你使用desede加密,实际是3des,但是由于密钥的两个8字节是相同的,退化成了des,我不知道为什么java对这个不报错?反正在python里就得改成des才行 |