md5加密

import hashlib
import os

def gen_md5(data):
    res = hashlib.md5(data.encode('utf-8')).hexdigest()

    return res

def handel_txt(name):
        with open(name,'r',encoding='utf-8') as f:
                with open('./'+name + '-res' +'.txt','w',encoding = 'utf-8') as f1:
                        sq = [gen_md5(line.strip())+'\n' for line in f.readlines()]
                        print(len(sq))
                        f1.writelines(sq)
                        print('done')


def main():
        li = os.listdir()

        for file_name in li:
                if file_name.endswith('.txt'):
                        handel_txt(file_name)

if __name__ == '__main__':
        main()

 

posted @ 2018-12-27 20:36  Erick-LONG  阅读(157)  评论(0编辑  收藏  举报