From 98ca35501c20a1cb5070b0e257edcdf49dc174bd Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Sun, 14 Oct 2018 23:25:32 +0200 Subject: [PATCH] Improved output of gcksum. --- gcksum.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gcksum.py b/gcksum.py index 1023e36..6c4765e 100644 --- a/gcksum.py +++ b/gcksum.py @@ -11,6 +11,7 @@ print("Opening {}".format(FILE)) csum_pre = 0 csum = 0 +last_byte = 0xff with open(FILE, "rb") as f: while True: @@ -21,11 +22,18 @@ with open(FILE, "rb") as f: csum &= 0xff if len(block) < 1024: print("End reached.") + last_byte = unpack("B", block[-1:])[0] break print("Sum of all bytes: {:02x}".format(csum)) -print("Sum without last: {:02x}".format(csum_pre)) +if csum == 0: + print("CHECKSUM VALID.") +else: + print("CHECKSUM INVALID!!! (Or GCD or other type.)") + +#print("Sum without last: {:02x}".format(csum_pre)) expected_cksum = ( 0x100 - csum_pre ) & 0xff print("Expected last byte: {:02x}".format(expected_cksum)) +print("Actual last byte: {:02x}".format(last_byte))