本文整理汇总了C++中Bignum::ToString方法的典型用法代码示例。如果您正苦于以下问题:C++ Bignum::ToString方法的具体用法?C++ Bignum::ToString怎么用?C++ Bignum::ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bignum
的用法示例。
在下文中一共展示了Bignum::ToString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
static Bignum resultModulus(0);
uint32_t numBits = DEFAULT_MODULUS_SIZE;
ofstream outfile;
char* outfileName;
bool writeToFile = false;
while ((argc > 1) && (argv[1][0] == '-'))
{
switch (argv[1][1])
{
case 'b':
numBits = atoi(argv[2]);
++argv;
--argc;
break;
case 'o':
outfileName = argv[2];
writeToFile = true;
break;
case 'h':
usage();
break;
default:
printf("Wrong Argument: %s\n", argv[1]);
usage();
break;
}
++argv;
--argc;
}
if (numBits < MIN_MODULUS_SIZE) {
cout << "Modulus is below minimum length (" << MIN_MODULUS_SIZE << ") bits" << endl;
return(0);
}
PrintWarning();
cout << "Modulus size set to " << numBits << " bits." << endl;
cout << "Generating parameters. This may take a few minutes..." << endl;
// Generate two safe primes "p" and "q"
Bignum *p, *q;
p = new Bignum(0);
q = new Bignum(0);
*p = Bignum::generatePrime(numBits / 2, true);
*q = Bignum::generatePrime(numBits / 2, true);
// Multiply to compute N
resultModulus = (*p) * (*q);
// Wipe out the factors
delete p;
delete q;
// Convert to a hexidecimal string
std::string resultHex = resultModulus.ToString(16);
cout << endl << "N = " << endl << resultHex << endl;
if (writeToFile) {
try {
outfile.open (outfileName);
outfile << resultHex;
outfile.close();
cout << endl << "Result has been written to file '" << outfileName << "'." << endl;
} catch (std::runtime_error &e) {
cout << "Unable to write to file:" << e.what() << endl;
}
}
}