From 773d7f6366f01b39e06d631072a08893fdce0526 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Mon, 24 Apr 2023 08:29:10 +0200 Subject: [PATCH] md5-analyzer init --- src/basic-decrypt.py | 8 +++----- src/calchash.py | 29 ----------------------------- src/md5-analyzer.py | 26 ++++++++++++++++++++++++++ src/trash-hash.py | 6 +++--- 4 files changed, 32 insertions(+), 37 deletions(-) delete mode 100755 src/calchash.py create mode 100755 src/md5-analyzer.py diff --git a/src/basic-decrypt.py b/src/basic-decrypt.py index 34712a4..67ab9f7 100755 --- a/src/basic-decrypt.py +++ b/src/basic-decrypt.py @@ -1,14 +1,12 @@ #!/usr/bin/env python3 - """ This script is really bad and hacky, don't expect it to do anything. you also need the chiffrat.txt file in the same directory. -License: MIT -author: Christoph J. Scherr -source: https://git.cscherr.de/PlexSheep/python-dhbw/src/branch/master/src/basic-decrypt.py +@license: MIT +@author: Christoph J. Scherr +@source: https://git.cscherr.de/PlexSheep/python-dhbw/src/branch/master/src/basic-decrypt.py """ - MAX_IN_LINE = 16 DE_MOST_COMMON = ['E', 'N', 'I', 'R', 'A'] EN_MOST_COMMON = ['E', 'T', 'A', 'O', 'I'] diff --git a/src/calchash.py b/src/calchash.py deleted file mode 100755 index 0aaa8da..0000000 --- a/src/calchash.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python3 -# this is literal garbage -# does not even work for the bad hash -def calcHash(): - message = list('A' * 4) - - accu = int("a5a5a5a55a5a5a5a55555555aaaaaaaa", 16) - - for i in range(0, len(message)): - message[i] = hex(ord(message[i]))[2:] - - if len(message) % 16 != 0: - remainder = -((len(message) % 16) - 16); - for i in range(0, remainder): - message.append("FF") - - chunks = [] - - for i in range(0, len(message), 16): - chunk = "".join(message[i:i+16]) - chunks.append(chunk) - - for B in chunks: - accu = accu ^ int(B, 16) - - print(accu) - return accu - -calcHash() diff --git a/src/md5-analyzer.py b/src/md5-analyzer.py new file mode 100755 index 0000000..5c02e35 --- /dev/null +++ b/src/md5-analyzer.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +""" +A small script to help analyze the md5 hash function. + +@author Christoph J. Scherr +@license MIT +@source: https://git.cscherr.de/PlexSheep/python-dhbw/src/branch/master/src/md5-analyzer.py +""" +import argparse +import hashlib + +def main(): + parser = argparse.ArgumentParser(prog="md5-analyzer", description='md5 analyzer for a cryptography assignment') + parser.add_argument('--hash', type=str, + help='an input that should be hashed.') + args = parser.parse_args() + if args.hash: + print("Hash for '%s':\n%s" % ( + args.hash, + hashlib.md5(args.hash.encode()).digest().hex() + )) + + + +if __name__ == "__main__": + main() diff --git a/src/trash-hash.py b/src/trash-hash.py index c34f876..5d3d523 100755 --- a/src/trash-hash.py +++ b/src/trash-hash.py @@ -2,9 +2,9 @@ """ Dirty hash we covered in an excercise for Week 16 of 2023 in cryptography -author: Christoph J. Scherr -version control at: https://git.cscherr.de/PlexSheep/python-dhbw/src/branch/master/src/trash-hash.py -License: MIT +@author: Christoph J. Scherr +@source: https://git.cscherr.de/PlexSheep/python-dhbw/src/branch/master/src/trash-hash.py +@license: MIT """ import math import argparse