[英]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? 一旦我尝试转换为十进制,就需要125位大小? 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? 但是,无符号long long最多只能包含64位,有没有办法存储此long整数,以便我可以用我想要的值对其取模 ?
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 . 通过将它们分成几部分来取模。例如,假设您要对37 ^ 11 mod 77取模,其中37 ^ 11给出答案1.77917621779460E17,以便得到这个..取一些小数代替11,得到11整数值..把它分解成碎片... 37 ^ 11 mod 77可以写成(37 ^ 4 x 37 ^ 4 x 37 ^ 3 mod 77),所以可以解决它.. {(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 因此,通常xy mod n = {(x mod n)(y mod n)} mod n
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.