Minggu, 19 April 2020

Python Script for MD5 Checksum

Python script for MD5 checksum of large files.

1. Below is the information of the file that will be used for the MD5 checksum (the CentOS ISO file is approximately 4.39 GB):

2. Make sure the file path in the Python script matches the actual location of the file.
E:\ISO\CentOS-7-x86_64-DVD-2009.iso

3. Run the script using PowerShell or CMD:
python scriptfile_name.py

4. MD5 checksum result (appears after about 88 seconds):

Note: The speed of the checksum calculation depends on the device specifications. The higher the specifications, the faster the checksum process.


================================================
Sample Python Script
================================================

# -*- coding: utf-8 -*-
"""
MD5 Checksum Generator for Large Files
Created on Sat Nov 1 2025
"""

import hashlib

def get_MD5(file_path):
    """
    Calculate the MD5 checksum of a file in chunks.
    Efficient for very large files (e.g. ISO, ZIP, etc.).
    """
    chunk_size = 8192  # 8 KB per read
    h = hashlib.md5()

    with open(file_path, 'rb') as f:
        while chunk := f.read(chunk_size):
            h.update(chunk)

    return h.hexdigest()


if __name__ == "__main__":
    file_path = r"E:\ISO\CentOS-7-x86_64-DVD-2009.iso"
    print("MD5 Checksum:", get_MD5(file_path))

================================================

Related article (SHA Checksum): 
Thank you.

Tidak ada komentar:

Posting Komentar