【发布时间】:2010-09-12 13:35:01
【问题描述】:
我正在使用 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 文件,编译器会遍历并编译它将使用的所有必要文件。
我应该如何尝试编译上述程序以解决链接错误?
【问题讨论】:
-
Meta-answer:如果您使用的是 bigint 算法的库,那么问问自己为什么不使用整个 RSA 实现的库。例如,gnu.org/software/gnu-crypto 包含一个 RSA 实现。它与GMP具有相同的许可证。但是,它们没有与mattmccutchen.net/bigint 相同的许可证,在我看来,它已被置于美国的公共领域。
-
如果可能的话,除了娱乐或学习之外,永远不要编写自己的加密程序。有很多不明显的事情你可能会出错。
-
要计算 A^B mod C,不需要做真正的幂,使用modular exponentiation。这里有很多关于这个的问题:stackoverflow.com/questions/8496182/…stackoverflow.com/questions/8287144/…
标签: c++ rsa biginteger integer