MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / md5me

Function md5me

hashes/md5.py:90–146  ·  view source on GitHub ↗

[summary] Returns a 32-bit hash code of the string 'testString' Arguments: testString {[string]} -- [message]

(testString)

Source from the content-addressed store, hash-verified

88 return (i << s) ^ (i >> (32-s))
89
90def md5me(testString):
91 """[summary]
92 Returns a 32-bit hash code of the string 'testString'
93
94 Arguments:
95 testString {[string]} -- [message]
96 """
97
98 bs =''
99 for i in testString:
100 bs += format(ord(i),'08b')
101 bs = pad(bs)
102
103 tvals = [int(2**32 * abs(math.sin(i+1))) for i in range(64)]
104
105 a0 = 0x67452301
106 b0 = 0xefcdab89
107 c0 = 0x98badcfe
108 d0 = 0x10325476
109
110 s = [7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, \
111 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, \
112 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, \
113 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21 ]
114
115 for m in getBlock(bs):
116 A = a0
117 B = b0
118 C = c0
119 D = d0
120 for i in range(64):
121 if i <= 15:
122 #f = (B & C) | (not32(B) & D)
123 f = D ^ (B & (C ^ D))
124 g = i
125 elif i<= 31:
126 #f = (D & B) | (not32(D) & C)
127 f = C ^ (D & (B ^ C))
128 g = (5*i+1) % 16
129 elif i <= 47:
130 f = B ^ C ^ D
131 g = (3*i+5) % 16
132 else:
133 f = C ^ (B | not32(D))
134 g = (7*i) % 16
135 dtemp = D
136 D = C
137 C = B
138 B = sum32(B,leftrot32((A + f + tvals[i] + m[g]) % 2**32, s[i]))
139 A = dtemp
140 a0 = sum32(a0, A)
141 b0 = sum32(b0, B)
142 c0 = sum32(c0, C)
143 d0 = sum32(d0, D)
144
145 digest = reformatHex(a0) + reformatHex(b0) + reformatHex(c0) + reformatHex(d0)
146 return digest
147

Callers 1

testFunction · 0.85

Calls 6

padFunction · 0.85
getBlockFunction · 0.85
not32Function · 0.85
sum32Function · 0.85
leftrot32Function · 0.85
reformatHexFunction · 0.85

Tested by

no test coverage detected