# coding:utf-8 def getval(s,key,size,offset): val=0 if size<=0: val=1 if (1<<(key[offset]%6)) & s[key[offset]/6] !=0 else 0 else: for i in range(size): val_bit=1 if (1<<(key[i]%6)) & s[key[i]/6] !=0 else 0 val|=(val_bit<<i) return val def clearbits(s,key,size,offset): vals=s if size <=0: vals[key[offset]/6]&=(~(1<< (key[offset] % 6) ) ) else: for i in range(size): vals[key[i]/6]&=(~(1<< (key[i] % 6) ) ) return vals def fillval(s,key,size,val): vals=s for i in range(size): bit=(val>>i)&1 if bit==1: vals[key[i]/6]|=(1<< (key[i] % 6)) else: vals[key[i]/6]&=(~(1<< (key[i] % 6))) return vals key1=[5, 12, 19, 26, 33, 40, 47, 54, 61, 68, 75, 82, 89, 96, 103, 110, 117, 124, 177, 178] key2=[69, 76, 83, 90, 97, 104, 111, 118, 125, 132, 139, 146, 34, 41, 48, 55, 62] key3=[14, 28, 42, 56, 70, 84, 98, 112, 126] key4=[7, 21, 35, 49, 63, 77, 91, 105, 119, 133, 140] key5=[62, 126, 55, 48, 112, 41, 34, 98, 146, 139, 84, 132, 125, 70, 118, 111, 56, 104, 97, 42, 90, 83, 28, 76, 69, 14] key6=[14, 112, 41, 55, 48, 62, 126, 146, 34, 104, 118, 76, 125, 83, 97, 132, 42, 139, 56, 98, 69, 28, 111, 90, 70, 84] key7=[41, 112, 48, 55, 126, 62, 139, 146, 98, 34, 111, 118, 70, 125, 132, 84, 42, 97, 104, 56, 14, 69, 76, 28, 83, 90] def decode(str): charsmap='F9CgKpUzb8DhM@qVBEeiN$rWd6ajP%sX75GkQ&tYf4HmR*uZA3InS+vxc2JoT#wy' vals=[] for c in str: vals.append(charsmap.find(c)) return vals def encode(data): chars='' charsmap='F9CgKpUzb8DhM@qVBEeiN$rWd6ajP%sX75GkQ&tYf4HmR*uZA3InS+vxc2JoT#wy' for i in data: chars+=charsmap[i] return chars def format_code(str): if len(str)!=50: print 'length error' return code=[] for i in range(50): if i%5==0: code.append(str[i:i+5]) return '-'.join(code) def clear_code(str): return str.replace('-','') def getck(s): xorkey=[1207, 1860, 234, 839, 1586, 326, 346, 1164, 1593, 381, 1105, 444, 607, 1085, 512, 142, 263, 805, 1196, 18, 889, 52, 688, 1792, 734, 18, 65, 1110, 291, 218, 271, 172, 574, 770, 1874, 310, 660, 1121, 582, 1253, 469, 36, 212, 595, 807, 848, 717, 679, 1264, 428, 458, 338, 533, 291, 1274, 1144, 929, 190, 644, 38, 100, 146, 3588, 755] ck=0 v9=2**9-1 v3=2**6 v10=2**11-1 dst=clearbits(s,key4,11,0) v6=getval(dst,key3,9,0) v1=getval(dst,key2,17,0) ck = v10 & (v6 % v9 + v1) for i in range(len(s)): v5 = (v6 % v9 + dst[i]) % v3 ck ^= xorkey[v5] return v10&ck def keygen(Cdid,Customer=1,Vendor=1): data=decode(50*'y') s=fillval(data,key1,20,Customer) s=fillval(s,key2,17,Cdid) s=fillval(s,key3,9,Vendor) ck=getck(s) s=fillval(s,key4,11,ck) return format_code(encode(s)) #这是一个有效的安装密钥 instkey=clear_code('Xywxo-zyyww-noYVX-#wxnY-yy##o-yyyyx-yyyyy-yyyyy-yyyyy-yyyyy') ik=decode(instkey) #提取出来的用户号 Customer=getval(ik,key1,20,0) #提取出来的产品id-这个必须和对于的软件包一致 Cdid=getval(ik,key2,17,0) #提取出的厂商id Vendor=getval(ik,key3,9,0) print Customer,Cdid,Vendor #通过软件包的产品id直接生成序列号 print keygen(Cdid)