Skip to content

Commit cfae621

Browse files
author
Christian Bender
committed
I documented the md5 hash
1 parent a2b540f commit cfae621

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

hashes/md5.py

+34
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,30 @@ def rearrange(bitString32):
1010
return newString
1111

1212
def reformatHex(i):
13+
"""[summary]
14+
Converts the given integer into 8-digit hex number.
15+
16+
Arguments:
17+
i {[int]} -- [integer]
18+
"""
19+
1320
hexrep = format(i,'08x')
1421
thing = ""
1522
for i in [3,2,1,0]:
1623
thing += hexrep[2*i:2*i+2]
1724
return thing
1825

1926
def pad(bitString):
27+
"""[summary]
28+
Fills up the binary string to a 512 bit binary string
29+
30+
Arguments:
31+
bitString {[string]} -- [binary string]
32+
33+
Returns:
34+
[string] -- [binary string]
35+
"""
36+
2037
startLength = len(bitString)
2138
bitString += '1'
2239
while len(bitString) % 512 != 448:
@@ -26,6 +43,15 @@ def pad(bitString):
2643
return bitString
2744

2845
def getBlock(bitString):
46+
"""[summary]
47+
Iterator:
48+
Returns by each call a list of length 16 with the 32 bit
49+
integer blocks.
50+
51+
Arguments:
52+
bitString {[string]} -- [binary string >= 512]
53+
"""
54+
2955
currPos = 0
3056
while currPos < len(bitString):
3157
currPart = bitString[currPos:currPos+512]
@@ -34,6 +60,7 @@ def getBlock(bitString):
3460
mySplits.append(int(rearrange(currPart[32*i:32*i+32]),2))
3561
yield mySplits
3662
currPos += 512
63+
3764
def not32(i):
3865
i_str = format(i,'032b')
3966
new_str = ''
@@ -48,6 +75,13 @@ def leftrot32(i,s):
4875
return (i << s) ^ (i >> (32-s))
4976

5077
def md5me(testString):
78+
"""[summary]
79+
Returns a 32-bit hash code of the string 'testString'
80+
81+
Arguments:
82+
testString {[string]} -- [message]
83+
"""
84+
5185
bs =''
5286
for i in testString:
5387
bs += format(ord(i),'08b')

0 commit comments

Comments
 (0)