0
    #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
Justpee
  • 181
  • 1
  • 3
  • 11
  • You don't need the temporary array `arr`. Either use `message.c_str()` or (if the `digestString` modifies the contents) `&message[0]`. Or modify the function to accept a `std::string` object? – Some programmer dude Nov 04 '17 at 18:22

2 Answers2

2

You can do it by hand or use a library that provides big integers like https://mattmccutchen.net/bigint/

OznOg
  • 4,440
  • 2
  • 26
  • 35
2

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