1 LicenseID='CN123-12345-12345-67891' 2 # RequestCode='RL634-8363J-X7E8K-95XD3' 3 RequestCode = 'RW61C-NN6CR-HY7GG-36QL8' # 注意此处的RequestCode 4 import hashlib 5 B16 = '0123456789ABCDEF' 6 B30 = '123456789ABCDEFGHJKLMNPQRTVWXY' 7 def B(n,f,t): 8 xx = 0 9 for d in str(n):10 xx = xx * len(f) + f.index(d)11 res = ''12 while xx > 0:13 res=t[int(xx%len(t))]+res14 xx//=len(t)15 return res16 def S(D):17 r = B(''.join([c for i,c in enumerate(D) if i//2*2==i]),B16,B30)18 while len(r) < 17:19 r = '1' + r20 return r21 def A(c):22 return c[:5]+'-'+c[5:10]+'-'+c[10:15]+'-'+c[15:]23 h = hashlib.sha1()24 h.update(RequestCode.encode('utf-8')+LicenseID.encode('utf-8'))25 lichash=A(RequestCode[:3]+S(h.hexdigest().upper()) )26 data=[23,161,47,9]27 tmp=028 realcode=''29 for i in data:30 for j in lichash:31 tmp=(tmp*i+ord(j))&0xFFFFF32 realcode+=format(tmp,'=05X')33 tmp=034 D=B(realcode,B16,B30)35 while len(D) < 17:36 D = '1' + D37 print("The Activation Code is: "+A('AXX'+D))