python 批量生成随机字符串的hash值

2017-04-04  本文已影响0人  AlphaFei

python 批量生成随机字符串的hash值

需求

主要模块

代码实现

#To generate hash.txt
#Author:RobotGF


import hashlib
from random import Random

def random_str():
    randomlength=6
    str = ''
#    chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'
    chars='abcdefghijklmnopqrstuvwxyz0123456'
    length = len(chars) - 1
    random = Random()
    for i in range(randomlength):
        str+=chars[random.randint(0, length)]
    return str

hash=open("hash.txt","w+")
plain_hash=open("plain_hash.txt","w+")

num=10000
i=0
while i < num :
    str=random_str()
    sha1=hashlib.sha1(str)
    sha1_hex=sha1.hexdigest()
    str=sha1_hex+":"+str+"\n"
    sha1_hex += "\n"
    plain_hash.write(str)
    hash.write(sha1_hex)
    i += 1
hash.close()
plain_hash.close()
上一篇下一篇

猜你喜欢

热点阅读