![]() |
|
[Python] Rate my "md5 hash every line in text into a new file" script. - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Rate my "md5 hash every line in text into a new file" script. (/showthread.php?tid=6197843) |
Rate my "md5 hash every line in text into a new file" script. - Hammylein - Mar 18, 2022 Good Morning to y'all from a python beginner, I was just trying to turn a text file full of words into md5 to then test said md5'd file against my hashcat rule ideas. This is python script i came up with to turn my entire plaintext file into a md5 text file. Code import hashlibWhat could i improve visually if at all. Functionally it works as intended. Cheers RE: Rate my "md5 hash every line in text into a new file" script. - Faith Connors - Mar 20, 2022 imo: --take filename in from args (i.e. filename.txt, and make the output file filename_md5.txt --is the print() on line 11 actually needed? do note that ive had stdout be a bottleneck for my code (i.e. removing print statements has made my code run much faster in the past, specifically in old compsci assignments.) looks clean otherwise. short and simple. there is one inconsistent naming convention (f vs outfile, despite both representing a file handle) i dont like how you use operators lol, for the print() statements, the first '+' is surrounded with spaces to pad it and make it look nice, but the second '+' is just cramped in for no reason (and that style is repeated in the next line) if you get rid of the print() statement, you may as well also get rid of assigning the digest to 'md5hash' since you're only using it in the write() call anyway. RE: Rate my "md5 hash every line in text into a new file" script. - 3phase - Mar 23, 2022 (Mar 18, 2022 01:48 AM)Hammylein Wrote: Good Morning to y'all from a python beginner, Well, your code works as intended in a perfect conditions environment. if you get a wrong input file name (or path), your code crash, but it only crashes after it has already made the output file which makes no sense, cause the output file will be empty. Thats my version of your code - Code import hashlib- The input file path, can be relative to the main.py file or absolute path, both works ( but its path in both cases ) - output_path is derived from input_file name, less hassle for the user - Opening output file only after the program successfully read all lines from the input file ( also catching the error if the file does not exist) - Writing into file written in one line with joined "list comprehension", you decide if you like it or not, it's up to you if you're familiar with the syntax RE: Rate my "md5 hash every line in text into a new file" script. - cremetarte - Mar 24, 2022 Posting here to follow what people say. thanks for sharing the code. RE: Rate my "md5 hash every line in text into a new file" script. - foxegado - Mar 30, 2022 You could always do something like this so that it can do more than just md5... Code from __future__ import annotations |