简体   繁体   中英

How can i modulo a big integer value

    #include <string>
    #include <iostream>

    using namespace std;

    #include "md5.h"

    int main()
    {
        MD5 md5;

        string message = "secretU";
        char arr[message.size()];
        strcpy(arr, message.c_str());

        //encrypting the message "secretU", it will return a string of hexadecimals
        string result = md5.digestString(arr); 

        //print the result of the encrypted message.
        cout << result; 
        return 0;
    }

Result of the output in hexadecimals

1853c517b0e1095a341210f1a4b422e6

Once i tried to convert to Decimal, it needs 125 bit size? However, unsigned long long can only contain up to 64 bits, is there a way to store this long integer so that i can modulo it with the value i want?

Convert hexadecimals to decimal

32336430049777443053240099092194140902

您可以手工完成,也可以使用提供大整数的库,例如https://mattmccutchen.net/bigint/

Take the modulo by breaking them into pieces.. say for example you want to take modulo of 37^11 mod 77 in which 37^11 gives answer 1.77917621779460E17 so to get this .. take some small number in place of 11 which gives an integer value.. break it into pieces... 37^11 mod 77 can be written as (37^4 x 37^4 x 37^3 mod 77) so solve it as.. {(37^4 mod 77)(37^4 mod 77)(37^3 mod 77)} mod 77 . So, in general xy mod n = {(x mod n)(y mod n)} mod n

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM