forked from Zibri/gcd-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgcksum.py
More file actions
26 lines (21 loc) · 671 Bytes
/
gcksum.py
File metadata and controls
26 lines (21 loc) · 671 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Calculates the Byte-checksum of a file and
shows if it's (last Byte) correct or not.
"""
from grmn import ChkSum
import sys
FILE = sys.argv[1]
csum = ChkSum()
print("Reading {} ...".format(FILE), end="", flush=True)
csum.add_from_file(FILE, print_progress=True)
print(" done.")
print("Sum of all bytes: {:02x}".format(csum.get_sum()))
print("Last byte: {:02x}".format(csum.get_last_byte()))
if csum.is_valid():
print("☑ CHECKSUM VALID.")
else:
print("☒ CHECKSUM INVALID!!! (Or GCD or other type.)")
expected_cksum = csum.get_expected()
print("Expected last byte: {:02x}".format(expected_cksum))