2
2
import math
3
3
4
4
def rearrange (bitString32 ):
5
+ """[summary]
6
+ Regroups the given binary string.
7
+
8
+ Arguments:
9
+ bitString32 {[string]} -- [32 bit binary]
10
+
11
+ Raises:
12
+ ValueError -- [if the given string not are 32 bit binary string]
13
+
14
+ Returns:
15
+ [string] -- [32 bit binary string]
16
+ """
17
+
5
18
if len (bitString32 ) != 32 :
6
19
raise ValueError ("Need length 32" )
7
20
newString = ""
@@ -10,13 +23,30 @@ def rearrange(bitString32):
10
23
return newString
11
24
12
25
def reformatHex (i ):
26
+ """[summary]
27
+ Converts the given integer into 8-digit hex number.
28
+
29
+ Arguments:
30
+ i {[int]} -- [integer]
31
+ """
32
+
13
33
hexrep = format (i ,'08x' )
14
34
thing = ""
15
35
for i in [3 ,2 ,1 ,0 ]:
16
36
thing += hexrep [2 * i :2 * i + 2 ]
17
37
return thing
18
38
19
39
def pad (bitString ):
40
+ """[summary]
41
+ Fills up the binary string to a 512 bit binary string
42
+
43
+ Arguments:
44
+ bitString {[string]} -- [binary string]
45
+
46
+ Returns:
47
+ [string] -- [binary string]
48
+ """
49
+
20
50
startLength = len (bitString )
21
51
bitString += '1'
22
52
while len (bitString ) % 512 != 448 :
@@ -26,6 +56,15 @@ def pad(bitString):
26
56
return bitString
27
57
28
58
def getBlock (bitString ):
59
+ """[summary]
60
+ Iterator:
61
+ Returns by each call a list of length 16 with the 32 bit
62
+ integer blocks.
63
+
64
+ Arguments:
65
+ bitString {[string]} -- [binary string >= 512]
66
+ """
67
+
29
68
currPos = 0
30
69
while currPos < len (bitString ):
31
70
currPart = bitString [currPos :currPos + 512 ]
@@ -34,6 +73,7 @@ def getBlock(bitString):
34
73
mySplits .append (int (rearrange (currPart [32 * i :32 * i + 32 ]),2 ))
35
74
yield mySplits
36
75
currPos += 512
76
+
37
77
def not32 (i ):
38
78
i_str = format (i ,'032b' )
39
79
new_str = ''
@@ -48,6 +88,13 @@ def leftrot32(i,s):
48
88
return (i << s ) ^ (i >> (32 - s ))
49
89
50
90
def md5me (testString ):
91
+ """[summary]
92
+ Returns a 32-bit hash code of the string 'testString'
93
+
94
+ Arguments:
95
+ testString {[string]} -- [message]
96
+ """
97
+
51
98
bs = ''
52
99
for i in testString :
53
100
bs += format (ord (i ),'08b' )
0 commit comments