Convert 32-char md5 string to integer

后端 未结 5 668
情深已故
情深已故 2021-01-01 19:36

What\'s the most efficient way to convert an md5 hash to a unique integer to perform a modulus operation?

5条回答
  •  借酒劲吻你
    2021-01-01 20:02

    Since the solution language was not specified, Python is used for this example.

    import os
    import hashlib
    
    array = os.urandom(1 << 20)
    md5 = hashlib.md5()
    md5.update(array)
    digest = md5.hexdigest()
    number = int(digest, 16)
    
    print(number % YOUR_NUMBER)
    

提交回复
热议问题