From 85567c820f7a8b87eff5f646e29285bcf0cbe44c Mon Sep 17 00:00:00 2001 From: CodeZeroNull Date: Mon, 23 Sep 2024 15:07:10 +0200 Subject: [PATCH 01/18] added md5 and sha256 options --- hashTar.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/hashTar.py b/hashTar.py index 2834817..d2be4a5 100644 --- a/hashTar.py +++ b/hashTar.py @@ -10,21 +10,34 @@ """ -def checksum(file_to_hash): - hashresult = hashlib.sha1() +def checksum(file_to_hash, algorithm="sha1"): + if algorithm == "sha1": + hashresult = hashlib.sha1() + if algorithm == "md5": + hashresult = hashlib.md5() + if algorithm == "sha256": + hashresult = hashlib.sha256() + else: + print("Please choose a valid algorithm, options are: sha1, md5, sha256") + return for chunk in iter(lambda: file_to_hash.read(4096), b''): hashresult.update(chunk) return hashresult.hexdigest() -def hashtar(input_tar_file): +def hashtar(input_tar_file, algorithm="sha1"): with tarfile.open(input_tar_file) as tar_input: - algo = "sha1" # Getting ready for algorithm chooser - outputname = input_tar_file + '.' + algo + algorithm = "sha1" # Getting ready for algorithm chooser + outputname = input_tar_file + '.' + algorithm with open(outputname, 'w') as checksums_file: for member in tar_input.getmembers(): if member.isreg(): # skip if not file (folders are members, hashing them fails) with tar_input.extractfile(member) as _file: - checksums_file.write('{} ./{}\n'.format(checksum(_file), member.name)) + checksums_file.write('{} ./{}\n'.format(checksum(_file, algorithm), member.name)) if __name__ == '__main__': - hashtar(sys.argv[1]) + if len(sys.argv) == 2: + hashtar(sys.argv[1]) + if len(sys.argv) == 3: + hashtar(sys.argv[1], sys.argv[2]) + else: + print("Error! I need a target file and an optional algorithm.") From ef3d5f0a8e675b7c0f8d59102c71bd0c6c47bd1e Mon Sep 17 00:00:00 2001 From: CodeZeroNull Date: Mon, 23 Sep 2024 15:14:15 +0200 Subject: [PATCH 02/18] added non-tested changes --- hashTar.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hashTar.py b/hashTar.py index d2be4a5..6e2483e 100644 --- a/hashTar.py +++ b/hashTar.py @@ -5,17 +5,22 @@ """ This script calculates hashes for every file inside a tar file and creates a checksum file Usage: -python3 hashTar.py target-tar-file +python3 hashTar.py target-tar-file optional-algorithm + +Options for optional-algorithm are: +md5 +sha1 (default) +sha256 """ def checksum(file_to_hash, algorithm="sha1"): - if algorithm == "sha1": + if str(algorithm) == "sha1": hashresult = hashlib.sha1() - if algorithm == "md5": + if str(algorithm) == "md5": hashresult = hashlib.md5() - if algorithm == "sha256": + if str(algorithm) == "sha256": hashresult = hashlib.sha256() else: print("Please choose a valid algorithm, options are: sha1, md5, sha256") @@ -26,7 +31,6 @@ def checksum(file_to_hash, algorithm="sha1"): def hashtar(input_tar_file, algorithm="sha1"): with tarfile.open(input_tar_file) as tar_input: - algorithm = "sha1" # Getting ready for algorithm chooser outputname = input_tar_file + '.' + algorithm with open(outputname, 'w') as checksums_file: for member in tar_input.getmembers(): From c34ccc43a24a328ec95e7dfaacae083667cf67f6 Mon Sep 17 00:00:00 2001 From: CodeZeroNull Date: Mon, 23 Sep 2024 15:20:23 +0200 Subject: [PATCH 03/18] did some changes it works for sha256 but not the others --- hashTar.py | 5 ++++- test.tar.md5 | 7 +++++++ test.tar.sha256 | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test.tar.md5 create mode 100644 test.tar.sha256 diff --git a/hashTar.py b/hashTar.py index 6e2483e..b574c62 100644 --- a/hashTar.py +++ b/hashTar.py @@ -16,6 +16,7 @@ def checksum(file_to_hash, algorithm="sha1"): + print("Algorithm from checksum: ", algorithm) if str(algorithm) == "sha1": hashresult = hashlib.sha1() if str(algorithm) == "md5": @@ -30,6 +31,7 @@ def checksum(file_to_hash, algorithm="sha1"): return hashresult.hexdigest() def hashtar(input_tar_file, algorithm="sha1"): + print("Algorithm from hashtar: ", algorithm) with tarfile.open(input_tar_file) as tar_input: outputname = input_tar_file + '.' + algorithm with open(outputname, 'w') as checksums_file: @@ -41,7 +43,8 @@ def hashtar(input_tar_file, algorithm="sha1"): if __name__ == '__main__': if len(sys.argv) == 2: hashtar(sys.argv[1]) - if len(sys.argv) == 3: + elif len(sys.argv) == 3: + print("Algorithm from name-main: ", sys.argv[2]) hashtar(sys.argv[1], sys.argv[2]) else: print("Error! I need a target file and an optional algorithm.") diff --git a/test.tar.md5 b/test.tar.md5 new file mode 100644 index 0000000..72719f9 --- /dev/null +++ b/test.tar.md5 @@ -0,0 +1,7 @@ +None ./LC-MS_data-collection_sequence.PNG +None ./LC-MS_example-chromatogram.PNG +None ./test-folder/copycat.PNG +None ./LC-MS_method_120min.pdf +None ./sample-prep_schematic_pierce-kit.png +None ./sample-prep_Pierce-Kit_MANUAL.pdf +None ./experimental_design.png diff --git a/test.tar.sha256 b/test.tar.sha256 new file mode 100644 index 0000000..c125030 --- /dev/null +++ b/test.tar.sha256 @@ -0,0 +1,7 @@ +af6b4a6ec075ac3e8bfce8efe6c769f86ea214d2da4271a8ea2ccba773ddc13f ./LC-MS_data-collection_sequence.PNG +d28baf357e0efdb22bdb12935f7d42e1f785041053f9c3a1e3b0a33243c27329 ./LC-MS_example-chromatogram.PNG +af6b4a6ec075ac3e8bfce8efe6c769f86ea214d2da4271a8ea2ccba773ddc13f ./test-folder/copycat.PNG +daedfcb4491590c83a57a7b2986592d5d6fe2078d6f62c90fa7c13569a500dd9 ./LC-MS_method_120min.pdf +081370da00b2eb334cd7bcf2eb2300e74cda0dab151a86a5cdf74c7686684b00 ./sample-prep_schematic_pierce-kit.png +6a610abc7968db8317d814c05ace0164d8161904b9281b8c355f703f8b2b4857 ./sample-prep_Pierce-Kit_MANUAL.pdf +91abb37ab680b5b664e80250691cfe0ff965be72835ef136170e3f81e05757d3 ./experimental_design.png From 7ec1167c378647b57c273e590694513fb7b0c0f2 Mon Sep 17 00:00:00 2001 From: CodeZeroNull Date: Mon, 23 Sep 2024 15:22:04 +0200 Subject: [PATCH 04/18] all working, had if instead of elif /faceplam --- hashTar.py | 4 ++-- test.tar.md5 | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/hashTar.py b/hashTar.py index b574c62..19e1762 100644 --- a/hashTar.py +++ b/hashTar.py @@ -19,9 +19,9 @@ def checksum(file_to_hash, algorithm="sha1"): print("Algorithm from checksum: ", algorithm) if str(algorithm) == "sha1": hashresult = hashlib.sha1() - if str(algorithm) == "md5": + elif str(algorithm) == "md5": hashresult = hashlib.md5() - if str(algorithm) == "sha256": + elif str(algorithm) == "sha256": hashresult = hashlib.sha256() else: print("Please choose a valid algorithm, options are: sha1, md5, sha256") diff --git a/test.tar.md5 b/test.tar.md5 index 72719f9..4d851b9 100644 --- a/test.tar.md5 +++ b/test.tar.md5 @@ -1,7 +1,7 @@ -None ./LC-MS_data-collection_sequence.PNG -None ./LC-MS_example-chromatogram.PNG -None ./test-folder/copycat.PNG -None ./LC-MS_method_120min.pdf -None ./sample-prep_schematic_pierce-kit.png -None ./sample-prep_Pierce-Kit_MANUAL.pdf -None ./experimental_design.png +e6a0c81a2898987449236a8079ee51d4 ./LC-MS_data-collection_sequence.PNG +e0895e7743ac5f95edd711e6023f26af ./LC-MS_example-chromatogram.PNG +e6a0c81a2898987449236a8079ee51d4 ./test-folder/copycat.PNG +63567d100e6938686cff21155989e12a ./LC-MS_method_120min.pdf +6dc88f40095541fb7c4859ac0f243586 ./sample-prep_schematic_pierce-kit.png +6ec91ca003a426a8c484325208eb5a17 ./sample-prep_Pierce-Kit_MANUAL.pdf +7b3b6df97c31c85f73d8251a49f5cbc3 ./experimental_design.png From 9ac69df373b2e01734359a9b34a46cb42023e9d9 Mon Sep 17 00:00:00 2001 From: CodeZeroNull Date: Mon, 23 Sep 2024 15:24:12 +0200 Subject: [PATCH 05/18] added md5 and sha256 to gitignore, removed debuggin prints from script --- .gitignore | 2 ++ hashTar.py | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index e139b6d..1808854 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ # Test files sha1sum-from-bash.txt test.tar.sha1 +test.tar.md5 +test.tar.sha256 test.tar test/ diff --git a/hashTar.py b/hashTar.py index 19e1762..a1edf36 100644 --- a/hashTar.py +++ b/hashTar.py @@ -16,7 +16,6 @@ def checksum(file_to_hash, algorithm="sha1"): - print("Algorithm from checksum: ", algorithm) if str(algorithm) == "sha1": hashresult = hashlib.sha1() elif str(algorithm) == "md5": @@ -31,7 +30,6 @@ def checksum(file_to_hash, algorithm="sha1"): return hashresult.hexdigest() def hashtar(input_tar_file, algorithm="sha1"): - print("Algorithm from hashtar: ", algorithm) with tarfile.open(input_tar_file) as tar_input: outputname = input_tar_file + '.' + algorithm with open(outputname, 'w') as checksums_file: @@ -44,7 +42,6 @@ def hashtar(input_tar_file, algorithm="sha1"): if len(sys.argv) == 2: hashtar(sys.argv[1]) elif len(sys.argv) == 3: - print("Algorithm from name-main: ", sys.argv[2]) hashtar(sys.argv[1], sys.argv[2]) else: print("Error! I need a target file and an optional algorithm.") From 08834194b59f83684ada0c9542a8e534635b573e Mon Sep 17 00:00:00 2001 From: CodeZeroNull Date: Mon, 23 Sep 2024 15:31:23 +0200 Subject: [PATCH 06/18] added test of valid algorithm before creating checsum file --- hashTar.py | 14 +++++++------- test.tar.sha555 | 0 2 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 test.tar.sha555 diff --git a/hashTar.py b/hashTar.py index a1edf36..a49fc3b 100644 --- a/hashTar.py +++ b/hashTar.py @@ -13,23 +13,23 @@ sha256 """ - +algorithms = ["sha1", "md5", "sha256"] def checksum(file_to_hash, algorithm="sha1"): - if str(algorithm) == "sha1": + if algorithm == "sha1": hashresult = hashlib.sha1() - elif str(algorithm) == "md5": + elif algorithm == "md5": hashresult = hashlib.md5() - elif str(algorithm) == "sha256": + elif algorithm == "sha256": hashresult = hashlib.sha256() - else: - print("Please choose a valid algorithm, options are: sha1, md5, sha256") - return for chunk in iter(lambda: file_to_hash.read(4096), b''): hashresult.update(chunk) return hashresult.hexdigest() def hashtar(input_tar_file, algorithm="sha1"): + if algorithm not in algorithms: + print("Please choose a valid algorithm, options are: sha1, md5, sha256") + sys.exit() with tarfile.open(input_tar_file) as tar_input: outputname = input_tar_file + '.' + algorithm with open(outputname, 'w') as checksums_file: diff --git a/test.tar.sha555 b/test.tar.sha555 new file mode 100644 index 0000000..e69de29 From 37058bb3dafff223d9b43fd5baa059cdc7f5dc2e Mon Sep 17 00:00:00 2001 From: CodeZeroNull Date: Mon, 23 Sep 2024 15:33:43 +0200 Subject: [PATCH 07/18] added all test fiesl to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1808854..0414ebd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ test.tar.md5 test.tar.sha256 test.tar test/ +test* # Byte-compiled / optimized / DLL files __pycache__/ From 77185a470db39b820cb029525d48cde4869899ad Mon Sep 17 00:00:00 2001 From: CodeZeroNull Date: Mon, 23 Sep 2024 15:34:42 +0200 Subject: [PATCH 08/18] updated --- .gitignore | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 0414ebd..94cfad1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,9 @@ # Test files sha1sum-from-bash.txt -test.tar.sha1 -test.tar.md5 -test.tar.sha256 test.tar +test.tar.* test/ -test* + # Byte-compiled / optimized / DLL files __pycache__/ From b3175a840b0eb8d126dc9789d158da09e4658bc5 Mon Sep 17 00:00:00 2001 From: CodeZeroNull Date: Tue, 24 Sep 2024 09:13:03 +0200 Subject: [PATCH 09/18] updated gitignore --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 94cfad1..bd5bc7a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ # Test files sha1sum-from-bash.txt -test.tar -test.tar.* +test.* test/ From 6348a29d91235e2d182c4b441fc5b4e9181f119b Mon Sep 17 00:00:00 2001 From: CodeZeroNull Date: Tue, 24 Sep 2024 09:24:11 +0200 Subject: [PATCH 10/18] Files removed from .gitignore --- test.tar.md5 | 7 ------- test.tar.sha256 | 7 ------- test.tar.sha555 | 0 3 files changed, 14 deletions(-) delete mode 100644 test.tar.md5 delete mode 100644 test.tar.sha256 delete mode 100644 test.tar.sha555 diff --git a/test.tar.md5 b/test.tar.md5 deleted file mode 100644 index 4d851b9..0000000 --- a/test.tar.md5 +++ /dev/null @@ -1,7 +0,0 @@ -e6a0c81a2898987449236a8079ee51d4 ./LC-MS_data-collection_sequence.PNG -e0895e7743ac5f95edd711e6023f26af ./LC-MS_example-chromatogram.PNG -e6a0c81a2898987449236a8079ee51d4 ./test-folder/copycat.PNG -63567d100e6938686cff21155989e12a ./LC-MS_method_120min.pdf -6dc88f40095541fb7c4859ac0f243586 ./sample-prep_schematic_pierce-kit.png -6ec91ca003a426a8c484325208eb5a17 ./sample-prep_Pierce-Kit_MANUAL.pdf -7b3b6df97c31c85f73d8251a49f5cbc3 ./experimental_design.png diff --git a/test.tar.sha256 b/test.tar.sha256 deleted file mode 100644 index c125030..0000000 --- a/test.tar.sha256 +++ /dev/null @@ -1,7 +0,0 @@ -af6b4a6ec075ac3e8bfce8efe6c769f86ea214d2da4271a8ea2ccba773ddc13f ./LC-MS_data-collection_sequence.PNG -d28baf357e0efdb22bdb12935f7d42e1f785041053f9c3a1e3b0a33243c27329 ./LC-MS_example-chromatogram.PNG -af6b4a6ec075ac3e8bfce8efe6c769f86ea214d2da4271a8ea2ccba773ddc13f ./test-folder/copycat.PNG -daedfcb4491590c83a57a7b2986592d5d6fe2078d6f62c90fa7c13569a500dd9 ./LC-MS_method_120min.pdf -081370da00b2eb334cd7bcf2eb2300e74cda0dab151a86a5cdf74c7686684b00 ./sample-prep_schematic_pierce-kit.png -6a610abc7968db8317d814c05ace0164d8161904b9281b8c355f703f8b2b4857 ./sample-prep_Pierce-Kit_MANUAL.pdf -91abb37ab680b5b664e80250691cfe0ff965be72835ef136170e3f81e05757d3 ./experimental_design.png diff --git a/test.tar.sha555 b/test.tar.sha555 deleted file mode 100644 index e69de29..0000000 From 7e02ae23ed3498b1c7deed6818b8d7ed3e7ffb30 Mon Sep 17 00:00:00 2001 From: CodeZeroNull Date: Tue, 24 Sep 2024 09:27:09 +0200 Subject: [PATCH 11/18] added note on md5 --- hashTar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hashTar.py b/hashTar.py index a49fc3b..dc365e1 100644 --- a/hashTar.py +++ b/hashTar.py @@ -7,7 +7,7 @@ Usage: python3 hashTar.py target-tar-file optional-algorithm -Options for optional-algorithm are: +Options for optional-algorithm are (md5 is not available in -- rare -- FIPS compliant Python): md5 sha1 (default) sha256 From de323f4fcb12a49e3cea1183f36b0ff89eb5c037 Mon Sep 17 00:00:00 2001 From: CodeZeroNull Date: Tue, 24 Sep 2024 09:49:26 +0200 Subject: [PATCH 12/18] Increased verbosity when running script fails to mention available algorithms --- hashTar.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hashTar.py b/hashTar.py index dc365e1..6bb7e97 100644 --- a/hashTar.py +++ b/hashTar.py @@ -45,3 +45,4 @@ def hashtar(input_tar_file, algorithm="sha1"): hashtar(sys.argv[1], sys.argv[2]) else: print("Error! I need a target file and an optional algorithm.") + print("Options for algorithm are:", algorithms) From e726ec096ecbf1d4360c687eef597e1e69122c99 Mon Sep 17 00:00:00 2001 From: CodeZeroNull Date: Tue, 24 Sep 2024 10:28:01 +0200 Subject: [PATCH 13/18] added sha3_512 --- hashTar.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hashTar.py b/hashTar.py index 6bb7e97..d95f187 100644 --- a/hashTar.py +++ b/hashTar.py @@ -11,9 +11,9 @@ md5 sha1 (default) sha256 - +sha3_512" """ -algorithms = ["sha1", "md5", "sha256"] +algorithms = ["md5", "sha1", "sha256", "sha3_512"] def checksum(file_to_hash, algorithm="sha1"): if algorithm == "sha1": @@ -22,11 +22,15 @@ def checksum(file_to_hash, algorithm="sha1"): hashresult = hashlib.md5() elif algorithm == "sha256": hashresult = hashlib.sha256() + elif algorithm == "sha3_512": # contrary to sha512, sha3-512 is not vulnerable to length extension attack + hashresult = hashlib.sha3_512() for chunk in iter(lambda: file_to_hash.read(4096), b''): hashresult.update(chunk) return hashresult.hexdigest() def hashtar(input_tar_file, algorithm="sha1"): + assert hasattr(hashlib, algorithm), "Invalid algorithm." # LBYL instead of EAFP, may be use + # try except instead if algorithm not in algorithms: print("Please choose a valid algorithm, options are: sha1, md5, sha256") sys.exit() From cab8aafbdd5a783b0f3ecbf42a6369395e80bb05 Mon Sep 17 00:00:00 2001 From: CodeZeroNull Date: Tue, 24 Sep 2024 10:29:55 +0200 Subject: [PATCH 14/18] algorithms to uppercase --- hashTar.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hashTar.py b/hashTar.py index d95f187..94e844f 100644 --- a/hashTar.py +++ b/hashTar.py @@ -13,7 +13,8 @@ sha256 sha3_512" """ -algorithms = ["md5", "sha1", "sha256", "sha3_512"] + +ALGORITHMS = ["md5", "sha1", "sha256", "sha3_512"] def checksum(file_to_hash, algorithm="sha1"): if algorithm == "sha1": @@ -31,7 +32,7 @@ def checksum(file_to_hash, algorithm="sha1"): def hashtar(input_tar_file, algorithm="sha1"): assert hasattr(hashlib, algorithm), "Invalid algorithm." # LBYL instead of EAFP, may be use # try except instead - if algorithm not in algorithms: + if algorithm not in ALGORITHMS: print("Please choose a valid algorithm, options are: sha1, md5, sha256") sys.exit() with tarfile.open(input_tar_file) as tar_input: @@ -49,4 +50,5 @@ def hashtar(input_tar_file, algorithm="sha1"): hashtar(sys.argv[1], sys.argv[2]) else: print("Error! I need a target file and an optional algorithm.") - print("Options for algorithm are:", algorithms) + print("Options for algorithm are:", ALGORITHMS) + From 5cc536afd5d7a49c4e7593fc4ba9cb24c509ebbc Mon Sep 17 00:00:00 2001 From: CodeZeroNull Date: Tue, 24 Sep 2024 10:31:05 +0200 Subject: [PATCH 15/18] update docstring --- hashTar.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hashTar.py b/hashTar.py index 94e844f..eff3645 100644 --- a/hashTar.py +++ b/hashTar.py @@ -11,7 +11,9 @@ md5 sha1 (default) sha256 -sha3_512" +sha3_512 + +Check hashlib documentation for other hashes that could be implemented here. """ ALGORITHMS = ["md5", "sha1", "sha256", "sha3_512"] From a216e53ffad9c798fe2fa876dccf9ef205db1f0c Mon Sep 17 00:00:00 2001 From: CodeZeroNull Date: Tue, 24 Sep 2024 10:37:15 +0200 Subject: [PATCH 16/18] a few changes, fixes #1 --- hashTar.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hashTar.py b/hashTar.py index eff3645..dcb9ef4 100644 --- a/hashTar.py +++ b/hashTar.py @@ -32,11 +32,14 @@ def checksum(file_to_hash, algorithm="sha1"): return hashresult.hexdigest() def hashtar(input_tar_file, algorithm="sha1"): - assert hasattr(hashlib, algorithm), "Invalid algorithm." # LBYL instead of EAFP, may be use - # try except instead if algorithm not in ALGORITHMS: - print("Please choose a valid algorithm, options are: sha1, md5, sha256") + print("Please choose a valid algorithm, options are:") + for algo in ALGORITHMS: + print(algo, end=" ") + print() sys.exit() + # Check if hashlib has the algorithm (e.g FIPS Python without MD5) + assert hasattr(hashlib, algorithm), "Invalid algorithm." with tarfile.open(input_tar_file) as tar_input: outputname = input_tar_file + '.' + algorithm with open(outputname, 'w') as checksums_file: From 56cae19f72f3e12256f0fcf96c29dd541fae20d6 Mon Sep 17 00:00:00 2001 From: CodeZeroNull Date: Tue, 24 Sep 2024 10:40:54 +0200 Subject: [PATCH 17/18] modified error messsage when running as script for better algorithms list --- hashTar.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hashTar.py b/hashTar.py index dcb9ef4..9c77795 100644 --- a/hashTar.py +++ b/hashTar.py @@ -55,5 +55,8 @@ def hashtar(input_tar_file, algorithm="sha1"): hashtar(sys.argv[1], sys.argv[2]) else: print("Error! I need a target file and an optional algorithm.") - print("Options for algorithm are:", ALGORITHMS) + print("Options for algorithm are:") + for algo in ALGORITHMS: + print(algo, end=" ") + print() From 9942ee8707e85675a4a72599b68400e9b9aceff1 Mon Sep 17 00:00:00 2001 From: CodeZeroNull Date: Tue, 24 Sep 2024 10:43:23 +0200 Subject: [PATCH 18/18] improved message when using as script --- hashTar.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hashTar.py b/hashTar.py index 9c77795..4df9049 100644 --- a/hashTar.py +++ b/hashTar.py @@ -54,7 +54,11 @@ def hashtar(input_tar_file, algorithm="sha1"): elif len(sys.argv) == 3: hashtar(sys.argv[1], sys.argv[2]) else: - print("Error! I need a target file and an optional algorithm.") + print("I need a target file and an optional algorithm.") + print() + print("Usage:") + print("python3 hashTar.py target-tar-file optional-algorithm") + print() print("Options for algorithm are:") for algo in ALGORITHMS: print(algo, end=" ")