标签:
安装Wing IDE
官网下载deb安装文件
1 import sha 2 import string 3 BASE2 = ‘01‘ 4 BASE10 = ‘0123456789‘ 5 BASE16 = ‘0123456789ABCDEF‘ 6 BASE30 = ‘123456789ABCDEFGHJKLMNPQRTVWXY‘ 7 BASE36 = ‘0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ‘ 8 BASE62 = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz‘ 9 BASEMAX = string.printable 10 def BaseConvert(number, fromdigits, todigits, ignore_negative = True): 11 """ converts a "number" between two bases of arbitrary digits 12 13 The input number is assumed to be a string of digits from the 14 fromdigits string (which is in order of smallest to largest 15 digit). The return value is a string of elements from todigits 16 (ordered in the same way). The input and output bases are 17 determined from the lengths of the digit strings. Negative 18 signs are passed through. 19 20 decimal to binary 21 >>> baseconvert(555,BASE10,BASE2) 22 ‘1000101011‘ 23 24 binary to decimal 25 >>> baseconvert(‘1000101011‘,BASE2,BASE10) 26 ‘555‘ 27 28 integer interpreted as binary and converted to decimal (!) 29 >>> baseconvert(1000101011,BASE2,BASE10) 30 ‘555‘ 31 32 base10 to base4 33 >>> baseconvert(99,BASE10,"0123") 34 ‘1203‘ 35 36 base4 to base5 (with alphabetic digits) 37 >>> baseconvert(1203,"0123","abcde") 38 ‘dee‘ 39 40 base5, alpha digits back to base 10 41 >>> baseconvert(‘dee‘,"abcde",BASE10) 42 ‘99‘ 43 44 decimal to a base that uses A-Z0-9a-z for its digits 45 >>> baseconvert(257938572394L,BASE10,BASE62) 46 ‘E78Lxik‘ 47 48 ..convert back 49 >>> baseconvert(‘E78Lxik‘,BASE62,BASE10) 50 ‘257938572394‘ 51 52 binary to a base with words for digits (the function cannot convert this back) 53 >>> baseconvert(‘1101‘,BASE2,(‘Zero‘,‘One‘)) 54 ‘OneOneZeroOne‘ 55 56 """ 57 if not ignore_negative and str(number)[0] == ‘-‘: 58 number = str(number)[1:] 59 neg = 1 60 else: 61 neg = 0 62 x = long(0) 63 for digit in str(number): 64 x = x * len(fromdigits) + fromdigits.index(digit) 65 66 res = ‘‘ 67 while x > 0: 68 digit = x % len(todigits) 69 res = todigits[digit] + res 70 x /= len(todigits) 71 72 if neg: 73 res = ‘-‘ + res 74 return res 75 76 def SHAToBase30(digest): 77 """Convert from a hexdigest form SHA hash into a more compact and 78 ergonomic BASE30 representation. This results in a 17 ‘digit‘ 79 number.""" 80 tdigest = ‘‘.join([ c for i, c in enumerate(digest) if i / 2 * 2 == i ]) 81 result = BaseConvert(tdigest, BASE16, BASE30) 82 while len(result) < 17: 83 result = ‘1‘ + result 84 85 return result 86 def AddHyphens(code): 87 """Insert hyphens into given license id or activation request to 88 make it easier to read""" 89 return code[:5] + ‘-‘ + code[5:10] + ‘-‘ + code[10:15] + ‘-‘ + code[15:] 90 91 LicenseID=‘ENX27-HWM6G-XYVFA-165PG‘ 92 #Copy the Request Code from the dialog 93 RequestCode=‘RW51N-LW9K6-T5GWP-YVBLP‘ 94 hasher = sha.new() 95 hasher.update(RequestCode) 96 hasher.update(LicenseID) 97 digest = hasher.hexdigest().upper() 98 lichash = RequestCode[:3] + SHAToBase30(digest) 99 lichash=AddHyphens(lichash) 100 101 #Calculate the Activation Code 102 data=[7,123,23,87] 103 tmp=0 104 realcode=‘‘ 105 for i in data: 106 for j in lichash: 107 tmp=(tmp*i+ord(j))&0xFFFFF 108 realcode+=format(tmp,‘=05X‘) 109 tmp=0 110 111 act30=BaseConvert(realcode,BASE16,BASE30) 112 while len(act30) < 17: 113 act30 = ‘1‘ + act30 114 act30=‘AXX‘+act30 115 act30=AddHyphens(act30) 116 print "The Activation Code is: "+act30 117 118 raw_input()
标签:
原文地址:http://www.cnblogs.com/mydebug/p/5034428.html