python2:

import string
import random
import sha BASE16 = '0123456789ABCDEF'
BASE30 = '123456789ABCDEFGHJKLMNPQRTVWXY' 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 = long(0)
for digit in str(number):
x = x * len(fromdigits) + fromdigits.index(digit) res = ''
while x > 0:
digit = x % len(todigits)
res = todigits[digit] + res
x /= len(todigits) if neg:
res = '-' + res
return res def AddHyphens(code):
return code[:5] + '-' + code[5:10] + '-' + code[10:15] + '-' + code[15:] 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 = '' + result
return result def loop(ecx, lichash):
part = 0
for c in lichash:
part = ecx * part + ord(c) & 1048575
return part rng = AddHyphens('CN' + randomstring(18, '123456789ABCDEFGHJKLMNPQRTVWXY'))
print 'License id: ' + rng
act30 = raw_input('Enter request code:')
lichash = act30
hasher = sha.new()
hasher.update(act30)
hasher.update(rng)
lichash = AddHyphens(lichash[:3] + SHAToBase30(hasher.hexdigest().upper()))
part5 = format(loop(23, lichash), '05x') + format(loop(161, lichash), '05x') + format(loop(47, lichash),
'05x') + format(loop(9, lichash),
'05x')
part5 = BaseConvert(part5.upper(), BASE16, BASE30)
while len(part5) < 17:
part5 = '' + part5 part5 = 'AXX' + part5
print 'Activation code: ' + AddHyphens(part5)

python2代码

python3:

import string
import random
import hashlib BASE16 = '0123456789ABCDEF'
BASE30 = '123456789ABCDEFGHJKLMNPQRTVWXY' 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 = 0
for digit in str(number):
x = x * len(fromdigits) + fromdigits.index(digit) res = ''
while x > 0:
digit = x % len(todigits)
res = todigits[digit] + res
x //= len(todigits) if neg:
res = '-' + res
return res def AddHyphens(code):
return code[:5] + '-' + code[5:10] + '-' + code[10:15] + '-' + code[15:] 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 = '' + result
return result def loop(ecx, lichash):
part = 0
for c in lichash:
part = ecx * part + ord(c) & 1048575
return part rng = AddHyphens('CN' + randomstring(18, '123456789ABCDEFGHJKLMNPQRTVWXY'))
print('License id: {}'.format(rng))
act30 = input('Enter request code:')
lichash = act30
hasher = hashlib.sha1()
act30 = act30.encode()
hasher.update(act30)
rng = rng.encode()
hasher.update(rng)
lichash = AddHyphens(lichash[:3] + SHAToBase30(hasher.hexdigest().upper()))
part5 = format(loop(23, lichash), '05x') + format(loop(161, lichash), '05x') + format(loop(47, lichash),
'05x') + format(loop(9, lichash),
'05x')
part5 = BaseConvert(part5.upper(), BASE16, BASE30)
while len(part5) < 17:
part5 = '' + part5 part5 = 'AXX' + part5
print('Activation code: {}'.format(AddHyphens(part5)))

python3代码

最新文章

  1. 让/etc/profile文件修改后立即生效
  2. jquery 赋值文本框输入框
  3. Digests from CG articales
  4. Session操作
  5. app快速开发
  6. ecshop修改产品详情 折扣倒计时时间
  7. vim 使用技巧
  8. VC++6.0注释快捷键设置
  9. POJ 3340 &amp;amp; HDU 2410 Barbara Bennett&amp;#39;s Wild Numbers(数学)
  10. Objective C Runtime 开发介绍
  11. The C5 Generic Collection Library for C# and CLI
  12. Python3基础 内嵌函数 简单示例
  13. JAVA基础面试(五)
  14. python!!!!惊了,这世上居然还有这么神奇的东西存在
  15. 读 vue 源码一 (为什么this.message能够访问data里面的message)
  16. lettcode笔记--Valid Parentheses
  17. C# 文件/文件夹压缩解压缩
  18. java的同步实现
  19. Android Data Binding Library
  20. 安装MySQL-python报错:_mysql.c(42) : fatal error C1083: Cannot open include file: &#39;config-win.h&#39;: No such file or directory或者 build\lib.win-amd64-2.7\_mysql.pyd : fatal error LNK1120: 56 unresolved externa

热门文章

  1. 开发avr单片机网络资源
  2. atitit.thumb生成高质量缩略图 php .net c++ java
  3. Typeface-为自定义字体提供字体内存缓存
  4. php的ord函数——解决中文字符截断问题
  5. 一款基于jQuery的带Tooltip表单验证的注册表单
  6. 燕十八mysql笔记
  7. 织梦dede模板中广告的去除方法?
  8. lmbench
  9. ubuntu samba 安装
  10. [ACM] FZU 2086 餐厅点餐 (枚举)