Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: calculate_md5_checksum.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- This script calculates the MD5 checksum for a given file.
- It uses the hashlib library to calculate the MD5 hash of the contents of the file
- and returns the hexadecimal representation of the hash.
- Example usage:
- filename = "file.txt" # File needs to be in the current working directory
- md5_checksum = calculate_md5(filename)
- print("MD5 Checksum For", filename, ":", md5_checksum)
- """
- import hashlib
- def calculate_md5(filename):
- """
- Calculate the MD5 checksum for a given file.
- Parameters:
- filename (str): The name of the file for which to calculate the checksum.
- Returns:
- str: The MD5 checksum of the file in hexadecimal format.
- Raises:
- FileNotFoundError: If the specified file does not exist.
- """
- with open(filename, "rb") as f:
- md5_hash = hashlib.md5()
- for chunk in iter(lambda: f.read(4096), b""):
- md5_hash.update(chunk)
- return md5_hash.hexdigest()
- # Example usage:
- filename = "file.txt" # File Needs To Be In The Current Working Directory
- md5_checksum = calculate_md5(filename)
- print("MD5 Checksum For ",filename,": ", md5_checksum)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement