Convert 32-char md5 string to integer

后端 未结 5 705
情深已故
情深已故 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:14

    If all you need is modulus, you don't actually need to convert it to 128-byte integer. You can go digit by digit or byte by byte, like this.

    mod=0
    for(i=0;i<32;i++)
    {
       digit=md5[i]; //I presume you can convert chart to digit yourself.
       mod=(mod*16+digit) % divider;
    }
    

提交回复
热议问题