每天一个py小程序 001生成激活码
来源:互联网 发布:linux route add 作用 编辑:程序博客网 时间:2024/06/05 10:51
第 0001 题:做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)?
#coding=utf-8"""第 0001 题:做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)?"""import randomimport hashlib#set(['SHA1', 'SHA224', 'SHA', 'SHA384', 'ecdsa-with-SHA1', 'SHA256', 'SHA512', 'md4', 'md5', 'sha1', 'dsaWithSHA', 'DSA-SHA', 'sha224', 'dsaEncryption', 'DSA', 'ripemd160', 'sha', 'MD5', 'MD4', 'sha384', 'sha256', 'sha512', 'RIPEMD160', 'whirlpool'])import osimport timedef salt(): return "%s"*5 % tuple([random.randint(10000000,99999999) for i in range(5)])def md5(str): m=hashlib.md5() m.update(str) return m.hexdigest()def main(): #print hashlib.algorithms_available res=[md5(salt() + str(time.time())) for i in range(200) ] path=os.path.split(os.path.realpath(__file__))[0]+"\\" #print path newpath=path+"res.txt" f=open(newpath,"w") for i in res: f.write(i+"\n") f.close() print "done" if __name__=='__main__': main()
程序主要分为两个部分,产生激活码,以及存入文件。
我们产生5组介于10000000~99999999之间的数字。并采用hashlib库中的md5加密 5组数字+当前的时间序列。
>>> help(hashlib.md5())Help on HASH object:class HASH(__builtin__.object) | A hash represents the object used to calculate a checksum of a | string of information. | | Methods: | | update() -- updates the current digest with an additional string | digest() -- return the current digest value | hexdigest() -- return the current digest as a string of hexadecimal digits | copy() -- return a copy of the current hash object | | Attributes: | | name -- the hash algorithm being used by this object | digest_size -- number of bytes in this hashes output | | Methods defined here: | | __repr__(...) | x.__repr__() <==> repr(x) | | copy(...) | Return a copy of the hash object. | | digest(...) | Return the digest value as a string of binary data. | | hexdigest(...) | Return the digest value as a string of hexadecimal digits. | | update(...) | Update this hash object's state with the provided string. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | block_size | | digest_size | | digestsize | | name | algorithm name.
0 0
- 每天一个py小程序 001生成激活码
- Python 练习册,每天一个小程序----------001使用 Python 如何生成多位随机数
- 每天一个小程序——第 0001 题:生成200个验证码
- 每天一个java小程序
- 每天一个java小程序
- 每天一个java小程序-2
- 每天一个java小程序-3
- 每天一个java小程序-4
- 每天一个java小程序-5
- 每天一个java小程序-6
- 每天一个java小程序-7
- 每天一个java小程序-8
- 每天一个java小程序-2
- 每天一个java小程序-3
- 每天一个java小程序-4
- 每天一个java小程序-5
- 每天一个java小程序-6
- 每天一个java小程序-7
- ActionBar的使用
- new way of ioctl --- unlocked_ioctl & compat_ioctl
- 2.9 属性组
- Palindrome Number
- Markdown 语法的简要规则
- 每天一个py小程序 001生成激活码
- Android toolBar详解
- Kali Linux网络配置
- 【算法导论】第六课 顺序统计,中值
- Java基础(异常)
- hdu 4685 (强联通 二分匹配 )
- Java 接口
- 一起学android之如何设置TextView中不同字段的字体颜色(22)
- Linux /dev/loop0文件详解