-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegrity_checker.py
More file actions
32 lines (27 loc) · 930 Bytes
/
integrity_checker.py
File metadata and controls
32 lines (27 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import hashlib
import os
def calculate_sha256(filepath):
"""
Reads a file in chunks and generates a SHA-256 hash.
Using chunks prevents memory crashes on large files.
"""
sha256_hash = hashlib.sha256()
try:
with open(filepath, "rb") as f:
# Read 4KB chunks
for byte_block in iter(lambda: f.read(4096), b""):
sha256_hash.update(byte_block)
return sha256_hash.hexdigest()
except FileNotFoundError:
return None
def check_integrity():
print("--- File Integrity Monitor (SHA-256) ---")
file_path = input("Enter the path of the file to check: ")
if os.path.exists(file_path):
file_hash = calculate_sha256(file_path)
print(f"\n[+] File: {file_path}")
print(f"[+] SHA-256 Hash: {file_hash}")
else:
print("\n[!] Error: File not found.")
if __name__ == "__main__":
check_integrity()