我正在使用 RSA 算法进行加密/解密,为了解密文件,您必须处理一些相当大的值。更具体地说,像
P = C^d % n
= 62^65 % 133
现在这确实是唯一不合适的计算。我曾尝试使用 Matt McCutchen 的 BigInteger 库,但在链接过程中出现很多编译器错误,例如:
encryption.o(.text+0x187):encryption.cpp: undefined reference to `BigInteger::BigInteger(int)'
encryption.o(.text+0x302):encryption.cpp: undefined reference to `operator<<(std::ostream&, BigInteger const&)'
encryption.o(.text$_ZNK10BigIntegermlERKS_[BigInteger::operator*(BigInteger const&) const]+0x63):encryption.cpp: undefined reference to `BigInteger::multiply(BigInteger const&, BigInteger const&)'
所以我想知道处理来自 RSA 算法的真正大整数的最佳方法是什么。
我听说有可能将你的变量声明为双长,所以...
long long decryptedCharacter;
但我不确定可以存储多大的整数。
例如,我尝试使用 dev C++ 编译并运行以下程序:
#include iostream
#include "bigint\BigIntegerLibrary.hh"
using namespace std;
int main()
{
BigInteger a = 65536;
cout << (a * a * a * a * a * a * a * a);
return 0;
}
然后我得到这些错误。
Derek,我认为通过包含 BigIntegerLibrary.hh
文件,编译器将遍历并编译它将使用的所有必要文件。
我应该如何尝试编译上述程序以解决链接错误?
最佳答案
Tomek,听起来您没有正确链接到 BigInteger 代码。我认为你应该解决这个问题而不是寻找一个新的图书馆。我查看了源代码,BigInteger::BigInteger(int)
是最明确定义的。简单的一瞥表明其他人也是如此。
您遇到的链接错误表明您要么忽略了编译 BigInteger 源代码,要么在链接时忽略了包含生成的目标文件。请注意,BigInteger 源使用“cc”扩展名而不是“cpp”,因此请确保您也在编译这些文件。
关于C++ 处理非常大的整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/124332/