python turns md5 into a 16 byte method

  • 2020-09-28 08:59:30
  • OfStack

hexdigest, provided in hashlib's hashlib library, returns a string of length 32.

16 bytes returned directly through digest with non-printable characters.

The question is, since md5sum is 128bit, which is 16 bytes, how do you turn python's string generation into 16 bytes?

See the following code


import hashlib
def get_md5(s):
 m = hashlib.md5(s)
 return m.hexdigest()
def convert_md5(origin):
 result = []
 s = ""
 for i in range(len(origin)):
   s += origin[i]
   if i %2 != 0 :
     int_hex = int(s, 16)
     result.append(int_hex)
     s = ""
 return result
if __name__=="__main__":
 sum = get_md5("hello world")
 print sum
 print len(sum)
 cv_sum = convert_md5(sum)
 print cv_sum
 print len(cv_sum)

output:


5eb63bbbe01eeed093cb22bb8f5acdc3 
32 
[94, 182, 59, 187, 224, 30, 238, 208, 147, 203, 34, 187, 143, 90, 205, 195] 
16

The converted list output is a value represented by each byte of the 10-byte output, for example, the last byte, 0xc3 == 195


Related articles: