md5-analyzer init

This commit is contained in:
Christoph J. Scherr 2023-04-24 08:29:10 +02:00
parent 46d7dd331a
commit 773d7f6366
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
4 changed files with 32 additions and 37 deletions

View File

@ -1,14 +1,12 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
""" """
This script is really bad and hacky, don't expect it to do anything. 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. you also need the chiffrat.txt file in the same directory.
License: MIT @license: MIT
author: Christoph J. Scherr <software@cscherr.de> @author: Christoph J. Scherr <software@cscherr.de>
source: https://git.cscherr.de/PlexSheep/python-dhbw/src/branch/master/src/basic-decrypt.py @source: https://git.cscherr.de/PlexSheep/python-dhbw/src/branch/master/src/basic-decrypt.py
""" """
MAX_IN_LINE = 16 MAX_IN_LINE = 16
DE_MOST_COMMON = ['E', 'N', 'I', 'R', 'A'] DE_MOST_COMMON = ['E', 'N', 'I', 'R', 'A']
EN_MOST_COMMON = ['E', 'T', 'A', 'O', 'I'] EN_MOST_COMMON = ['E', 'T', 'A', 'O', 'I']

View File

@ -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()

26
src/md5-analyzer.py Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env python3
"""
A small script to help analyze the md5 hash function.
@author Christoph J. Scherr <software@cscherr.de>
@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()

View File

@ -2,9 +2,9 @@
""" """
Dirty hash we covered in an excercise for Week 16 of 2023 in cryptography Dirty hash we covered in an excercise for Week 16 of 2023 in cryptography
author: Christoph J. Scherr <software@cscherr.de> @author: Christoph J. Scherr <software@cscherr.de>
version control at: https://git.cscherr.de/PlexSheep/python-dhbw/src/branch/master/src/trash-hash.py @source: https://git.cscherr.de/PlexSheep/python-dhbw/src/branch/master/src/trash-hash.py
License: MIT @license: MIT
""" """
import math import math
import argparse import argparse