使用两个函数进行密码散列Python

时间:2017-03-19 18:34:04

标签: function python-3.x hash

尝试创建一个只接受密码列表的脚本,然后以纯文本形式打印出来,并使用md5进行哈希处理。问题是我试图使用两个函数,但无法使它们正常工作。密码列表函数应接受密码列表作为参数,然后遍历列表中的每个项目并打印实际密码,逗号,然后是md5加密密码。 makemd5函数只是创建哈希值。

import hashlib
passwordlist = ["password","123456","12345678","1234","qwerty","12345",
"baseball","football","letmein","monkey","abc123","mustang","michael"]

def makemd5(key_string):

    new_key_string = key_string.encode('utf-8')

    return (hashlib.md5 ( new_key_string ).hexdigest())

def createmd5list(passwordlist):

    for key_string in passwordlist:

    return (key_string, makemd5)


def main():

    hashlist = createmd5list(passwordlist) 

    print(hashlist)

main ()

1 个答案:

答案 0 :(得分:0)

import hashlib
passwordlist = ["password","123456","12345678","1234","qwerty","12345",
"baseball","football","letmein","monkey","abc123","mustang","michael"]

def makemd5(key_string):

    new_key_string = key_string.encode('utf-8')

    return (hashlib.md5 ( new_key_string ).hexdigest())

def createmd5list(passwordlist):

    for passlist in passwordlist:
        hashlist = makemd5(passlist)
        print (passlist,",",hashlist)


def main():

    passlist = createmd5list(passwordlist) 

    print(passlist)


main ()