Returns the 32-char MD5 hash of a given message. Reference: https://en.wikipedia.org/wiki/MD5#Algorithm Arguments: message {[string]} -- [message] Returns: 32-char MD5 hash string >>> md5_me(b"") b'd41d8cd98f00b204e9800998ecf8427e' >>> md5_me(b"The qu
(message: bytes)
| 295 | |
| 296 | |
| 297 | def md5_me(message: bytes) -> bytes: |
| 298 | """ |
| 299 | Returns the 32-char MD5 hash of a given message. |
| 300 | |
| 301 | Reference: https://en.wikipedia.org/wiki/MD5#Algorithm |
| 302 | |
| 303 | Arguments: |
| 304 | message {[string]} -- [message] |
| 305 | |
| 306 | Returns: |
| 307 | 32-char MD5 hash string |
| 308 | |
| 309 | >>> md5_me(b"") |
| 310 | b'd41d8cd98f00b204e9800998ecf8427e' |
| 311 | >>> md5_me(b"The quick brown fox jumps over the lazy dog") |
| 312 | b'9e107d9d372bb6826bd81d3542a419d6' |
| 313 | >>> md5_me(b"The quick brown fox jumps over the lazy dog.") |
| 314 | b'e4d909c290d0fb1ca068ffaddf22cbd0' |
| 315 | |
| 316 | >>> import hashlib |
| 317 | >>> from string import ascii_letters |
| 318 | >>> msgs = [b"", ascii_letters.encode("utf-8"), "Üñîçø∂é".encode("utf-8"), |
| 319 | ... b"The quick brown fox jumps over the lazy dog."] |
| 320 | >>> all(md5_me(msg) == hashlib.md5(msg).hexdigest().encode("utf-8") for msg in msgs) |
| 321 | True |
| 322 | """ |
| 323 | |
| 324 | # Convert to bit string, add padding and append message length |
| 325 | bit_string = preprocess(message) |
| 326 | |
| 327 | added_consts = [int(2**32 * abs(sin(i + 1))) for i in range(64)] |
| 328 | |
| 329 | # Starting states |
| 330 | a0 = 0x67452301 |
| 331 | b0 = 0xEFCDAB89 |
| 332 | c0 = 0x98BADCFE |
| 333 | d0 = 0x10325476 |
| 334 | |
| 335 | shift_amounts = [ |
| 336 | 7, |
| 337 | 12, |
| 338 | 17, |
| 339 | 22, |
| 340 | 7, |
| 341 | 12, |
| 342 | 17, |
| 343 | 22, |
| 344 | 7, |
| 345 | 12, |
| 346 | 17, |
| 347 | 22, |
| 348 | 7, |
| 349 | 12, |
| 350 | 17, |
| 351 | 22, |
| 352 | 5, |
| 353 | 9, |
| 354 | 14, |
nothing calls this directly
no test coverage detected