Skip to main content

Calculate file hashes super fast!

Project description

File Hash Verification Tool

A Python-based multi-algorithm file hash calculation tool with GUI and intelligent chunking optimization. Supports multiple hash algorithms including MD5, SHA1, SHA256, SHA512. When calculating large files, the efficiency far exceeds system-built tools.

中文文档

Features

  • Multi-algorithm Support: Supports MD5, SHA1, SHA256, SHA512 and other hash algorithms
  • GUI Support: Uses Tkinter to provide file selection dialog and hash value input dialog
  • Command Line Fallback: Automatically falls back to command line input in non-GUI environments
  • Intelligent Chunking Optimization: Automatically adjusts read chunk size based on disk type (SSD/HDD)
  • Real-time Progress Display: Uses alive-progress library to show calculation progress bar
  • Hash Value Verification: Supports input of custom hash values for file verification and comparison
  • Cross-platform Compatibility: Supports Windows systems, non-Windows systems use default chunk size

Performance Comparison

Performance Comparison Demo

The larger the file, the more pronounced the difference becomes.

Installation Dependencies

pip install -r requirements.txt

Main dependencies:

  • tkinter - GUI support
  • alive-progress - Progress bar display
  • hashlib - Hash algorithm calculation

Usage

  1. Run the program:

    python main.py
    # On Windows, you can double-click to open directly
    
  2. Select hash algorithm

    • Choose MD5, SHA1, SHA256 or SHA512 algorithm in GUI
    • Select algorithm by number in non-GUI environments
  3. Select the file to calculate hash value

    • Select file through file selection dialog in GUI
    • Input file path through command line in non-GUI environments
  4. Input hash value to compare (optional)

    • Input corresponding hash value in dialog for verification
    • Leave blank to only display calculated hash value
  5. View results

    • Program will display calculation progress bar
    • Output file's hash value
    • If verification value was input, comparison result will be shown

Intelligent Chunking Optimization

The program automatically optimizes read chunk size based on the disk type where the file is located:

  • SSD: 512KB chunk size
  • HDD: 256KB chunk size
  • Default: 1MB chunk size (when disk type cannot be detected)

This optimization can improve calculation efficiency for large files, especially on different storage media.

Program Structure

  • get_ssd_or_hdd(): Detects system disk type (Windows only)
  • select_algorithm(): Selects hash algorithm
  • select_file(): File selection functionality
  • input_hash(): Hash value input functionality
  • _chunk_size(): Intelligent chunk size determination
  • calculate_hash_with_progress(): Hash calculation with progress bar
  • hash_diff(): Hash value comparison
  • main(): Main program logic

Usage Examples When Used as a Module

from hash_calculation import calculate_hash_with_progress

# Calculate hash value for a file
file_path = "path/to/your/file"
algorithm = "SHA256"
hash_value = calculate_hash_with_progress(file_path, algorithm)
print(f"{file_path}'s {algorithm} value is: {hash_value}")
from hash_calculation import hash_diff

file_path = "path/to/your/file"
algorithm = "SHA256"
hash_value = calculate_hash_with_progress(file_path, algorithm)
# Verify hash value for a file
compare_hash = "your_sha256_hash"
if hash_diff(hash_value, compare_hash):
    print(f"{file_path}'s {algorithm} value verification successful ✅")
else:
    print(f"{file_path}'s {algorithm} value verification failed ❌")
from hash_calculation import get_ssd_or_hdd

# Get disk types for all system disks (Windows only)
disk_types = get_ssd_or_hdd()
for disk, type in disk_types.items():
    print(f"Disk {disk}: {type}")

Notes

  • Project is mainly optimized for Windows systems
  • Non-Windows systems will use default chunk size
  • Appropriate permissions are required to access files and disk information
  • Supports all types of file formats
  • When running in virtual machines, accurate hard disk type may not be obtained

Project Origin

The built-in system tools are painfully slow at calculating hashes—fine for small files, but what about a 100 GB one?

I might be old and gray before it finishes, so I wrote this tool hoping it helps everyone.

Plus, there’s no visual progress bar, leaving you clueless about where things stand.

Moreover, I had to look for other tools to compare hash values, so I integrated that functionality into this program.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hash_calculation-0.0.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hash_calculation-0.0.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file hash_calculation-0.0.1.tar.gz.

File metadata

  • Download URL: hash_calculation-0.0.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for hash_calculation-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6c950c5b78e9b944e050f61c6f1022592b84eda86d50b2eb74983673913aec4c
MD5 7364e2cb3bf2566975ac114c6f6b45ba
BLAKE2b-256 22439fa086dbdf83a8177ff28de489980b121be96213f3d58464c91f462526ef

See more details on using hashes here.

File details

Details for the file hash_calculation-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for hash_calculation-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 daf5eb14d15dec65caa012e07901bb9f08705c20959bbe64413cf51ce412deb3
MD5 aa80a2d83ba4117066268e2f34d5cb0e
BLAKE2b-256 e75cc80c57bebdb9f7de5578f4257d4e6ac8320c3866082550507a80963d2a06

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page