python3 编写 WingPro7 注册机算法
wingpro是一款非常优秀的适用于python开发IDE软件
而且该软件的插件同样可以使用python语言编写,wingpro可以工作在Mac,Windows,Linux上
为此我使用python3写了个序列生成器,仅供学习算法使用
import random import string import hashlib BASE16 = ‘0123456789ABCDEF‘ BASE30 = ‘123456789ABCDEFGHJKLMNPQRTVWXY‘ def AddHyphens(code): return code[:5] + ‘-‘ + code[5:10] + ‘-‘ + code[10:15] + ‘-‘ + code[15:] def randomstring(size=20, chars=string.ascii_uppercase + string.digits): return (‘‘).join((random.choice(chars) for _ in range(size))) def BaseConvert(number, fromdigits, todigits, ignore_negative=True): if not ignore_negative and str(number)[0] == ‘-‘: number = str(number)[1:] neg = 1 else: neg = 0 x = int(0) for digit in str(number): x = x * len(fromdigits) + fromdigits.index(digit) res = ‘‘ while x > 0: digit = int(x % len(todigits)) res = todigits[digit] + res x //= len(todigits) if neg: res = ‘-‘ + res return res def SHAToBase30(digest): tdigest = (‘‘).join([c for i, c in enumerate(digest) if i // 2 * 2 == i]) result = BaseConvert(tdigest, BASE16, BASE30) while len(result) < 17: result = ‘1‘ + result return result def loop(ecx, lichash): part = 0 for c in lichash: part = ecx * part + ord(c) & 1048575 return part def getLicenseId() -> str: licenseId = AddHyphens(‘CN‘ + randomstring(18, ‘123456789ABCDEFGHJKLMNPQRTVWXY‘)) return licenseId def generateCode(licenseId: str, requestCode: str) -> str: lichash = requestCode lichash = AddHyphens(lichash[:3] + SHAToBase30(hashlib.sha1((requestCode + licenseId).encode("utf-8")).hexdigest().upper())) part5 = format(loop(221, lichash), ‘05x‘) + format(loop(13, lichash), ‘05x‘) + format(loop(93, lichash), ‘05x‘) + format(loop(27, lichash), ‘05x‘) part5 = BaseConvert(part5.upper(), BASE16, BASE30) while len(part5) < 17: part5 = ‘1‘ + part5 part5 = ‘AXX‘ + part5 return AddHyphens(part5) if __name__=="__main__": licenseId=getLicenseId() print("License Id:"+licenseId) requestCode=input("requestCode:") print("generateCode:"+generateCode(licenseId,requestCode))
相关推荐
chuckchen 2020-10-31
Will0 2020-10-12
Dreamhome 2020-10-09
xirongxudlut 2020-09-28
星辰大海的路上 2020-09-13
chaochao 2020-08-31
猪猪侠喜欢躲猫猫 2020-08-17
快递小可 2020-08-16
shengge0 2020-07-26
巩庆奎 2020-07-21
张文倩数据库学生 2020-07-19
xirongxudlut 2020-07-18
Ericbig 2020-07-18
kyelu 2020-07-09
liangzhouqu 2020-07-07
GuoSir 2020-06-28
chaigang 2020-06-27
pythonxuexi 2020-06-25