how to generate sha256 hash for each line of my txt file | using python version 3.6.4 - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: how to generate sha256 hash for each line of my txt file | using python version 3.6.4 (/thread-8237.html) |
how to generate sha256 hash for each line of my txt file | using python version 3.6.4 - rajtekken5 - Feb-11-2018 I am creating a project for generating sha256 hash from text file I want to read each line from my text file and generate sha256 for it. Here is the code i written but it is not correct. please see and suggest me. my text file contains: apple banana grape watermelon stawberry my Code is : import hashlib f = open("D:/12/1.txt",'r') x = f.readline() while(x !=""): hash_object = hashlib.sha256(b'x') hex_dig = hash_object.hexdigest() print(x.strip(),"",hex_dig) x= f.readline() input("Successful..Press enter to exit") RE: how to generate sha256 hash for each line of my txt file | using python version 3.6.4 - snippsat - Feb-11-2018 This should do it. import hashlib with open('fruit.txt') as f: for line in f: line = line.strip() print(f'{hashlib.sha256(line.encode()).hexdigest()} --> {line}')
RE: how to generate sha256 hash for each line of my txt file | using python version 3.6.4 - rajtekken5 - Feb-11-2018 If my list contain some more lines like 100 words or more. if i want to output a line in my output.txt --for-- Which sha256 starts with the prefix 'e8' So its output the raw text & sha256 in output.txt |