Python how to convert MD5 to 16 bytes

Source: Internet
Author: User

The hexdigest provided in the Python Hashlib library returns a string of length 32.

Md5sum is 128bit, which is 16 bytes, how do I convert a python string to 16 bytes?

Take a look at the following code

import hashlibdef 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 resultif __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 output list is the value represented by each byte of the 10 binary output, for example, the last byte, 0xc3 = = 195

Python how to convert MD5 to 16 bytes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.