2
回答
sql assistant 6.0 keygen
华为云实践训练营,热门技术免费实践!>>>   
import random
import string
import sys
  
def getStrSum(str) :
    sum=0
    for c in str:
           sum+=string.atoi(c)
    return sum
          
def getKey1for6(str1,str2) :
    return processKey1for6(str1)+processKey1for6(str2)

def processKey1for6(str) :
  sum=0
  for c in str:
      sum+=ord(c)
  return "%04X"%(1000*(sum%9)+sum)


def getKey3(num):
  key=""
  str = "123456789abcdefghikjlmnopqrstuv".upper();
  base=1073741824
  while base>0:
    if num/base>0 :
      i=num/base
      num=num-i*base
      base/=32
      key+=str[i-1]
     else :
       base/=32
       key+="0"
       continue
  return key
   
def genLicense() :
  key2 = "%06d"%random.randint(0,999999)
  licType="E"
  strMOrL="M"

  key4LastTwo=string.join(random.sample("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 2)).replace(" ","")
  key4=licType+strMOrL+key4LastTwo
  key5FirstTwo=getStrSum(key2)+22
  bigStrVal=100000*key5FirstTwo+0x80000000-1+string.atoi(key2[-2:])
  key5LastTwo=getStrSum(str(bigStrVal))+22
  key5=str(key5FirstTwo)+str(key5LastTwo)
  key3=getKey3(bigStrVal)
  key1=getKey1for6(key2+key3,key4+key5)
  print key1+"-DD"+key2+"-"+key3+"-"+key4+"-"+key5

genLicense()
<无标签>
举报
ddatsh
发帖于6年前 2回/866阅

更新了一版

import random
import string
import sys

#生成指定位数随机字符串
def getRandomString(numOfStr):
	return string.join(random.sample("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", numOfStr)).replace(" ","")
		
#数值字符串各位累加和
def getStrIntSum(str) :
    return reduce(lambda x,y: x+y, [string.atoi(i) for i in str])
   
#字符串各位ASCII值累加和
def getStrAsciiSum(str) :
    return reduce(lambda x,y: x+y, [ord(i) for i in str])   
          
#key1 由2,3与4,5拼起来的字符串,运算得到每组4个字符          
def getKey1for6(str1,str2) :
    return processKey1for6(str1)+processKey1for6(str2)

def processKey1for6(str) :
	sum=getStrAsciiSum(str)
	return "%04X"%(1000*(sum%9)+sum)

def getKey1for5(str1,str2) :
    return processKey1for5(str1)+processKey1for5(str2)

def processKey1for5(str) :
	return "%04X"%getStrAsciiSum(str)
	
def getKey3(num):
	key=""
	str = "123456789abcdefghikjlmnopqrstuv".upper();
	base=1073741824
	while base>0:
		if num/base>0 :
			i=num/base
			num=num-i*base
			base/=32
			key+=str[i-1]
 		else :
 			base/=32
 			key+="0"
 			continue
	return key
		
	

   
def genLicense() :
	
	#step 1 key2是000000-999999随机6位数
	key2 = "%06d"%random.randint(0,999999)
	#print "key2 "+key2

	#step 2 key4 为4位,第一位是E,S,1,P,第二位L或M,表示是否带维护版,最后两位随机字符
	licType="E"
	strMOrL="M"

	key4LastTwo=getRandomString(2)
	key4=licType+strMOrL+key4LastTwo
	#print "key4 "+key4

	#step 3,根据key2后两位数值,加上100000*key5前两位
	key5FirstTwo=getStrIntSum(key2)+22
	bigStrVal=100000*key5FirstTwo+0x80000000-1+string.atoi(key2[-2:])
	key5LastTwo=getStrIntSum(str(bigStrVal))+22
	key5=str(key5FirstTwo)+str(key5LastTwo)
	#print bigStrVal
	#print "key5 "+key5
	#print key5FirstTwo

	key3=getKey3(bigStrVal)

	key1=getKey1for6(key2+key3,key4+key5)
	#key1=getKey1for5(key2+key3,key4+key5)

	print key1+"-"+getRandomString(2)+key2+"-"+key3+"-"+key4+"-"+key5
	#print key1+"-"+key2+"-"+key3+"-"+key4+"-"+key5

for i in range(1, 10):
	genLicense()


########测试
def fun2(str) :
    strFind="123456789abcdefghikjlmnopqrstuv".upper();
    str="2Y5N3F2"[::-1]
    sum=0
    base=1
    for c in str :
        idx=string.find(strFind, c,0,len(strFind))  
        if idx>-1 :
            sum+=base*(idx+1)
        base*=32
    print sum
顶部