C ++处理非常大的整数 [英] C++ handling very large integers

查看:602
本文介绍了C ++处理非常大的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用RSA算法进行加密/解密,为了解密文件,你必须处理一些很大的值。具体来说,

  P = C ^ d%n 
= 62 ^ 65%133

现在这是真正的唯一的计算。我尝试使用Matt McCutchen的BigInteger库,但是我在链接过程中遇到很多编译错误,例如:

 加密。 o(.text + 0x187):encryption.cpp:未定义引用`BigInteger :: BigInteger(int)'

encryption.o(.text + 0x302):encryption.cpp:undefined引用` operator<<<<<(std :: ostream&),BigInteger const&)'

encryption.o(.text $ _ZNK10BigIntegermlERKS_ [BigInteger :: operator *(BigInteger const& .cpp:未定义引用`BigInteger :: multiply(BigInteger const& BigInteger const&)'

所以我想知道什么是处理RSA算法产生的真正大整数的最好方法。



我听说一个可能性是声明你的变量为双长,所以...

  long long decryptedCharacter; 

但我不知道可以存储的整数有多大。






例如,我尝试使用dev C ++编译和运行以下程序:

  #include iostream 

#includebigint \BigIntegerLibrary.hh

using namespace std;

int main()
{
BigInteger a = 65536;
cout<< (a * a * a * a * a * a * a * a);
return 0;
}

那么我会得到这些错误。



Derek,我认为通过包含 BigIntegerLibrary.hh 文件,编译器会通过并编译它将使用的所有必需的文件。 p>

如何尝试编译上述程序以解决链接错误?

解决方案

元回答:



如果你使用一个库进行bigint运算,那么问自己为什么你不使用库RSA实施。



例如, http:// www。 gnu.org/software/gnu-crypto/ 包含RSA实施。它与GMP具有相同的许可证。



但是,他们没有与相同的许可证http://mattmccutchen.net/bigint/ ,我似乎已被放入美国的公共领域。


I am using the RSA Algorithm for encryption/decryption, and in order to decrypt the files you have to deal with some pretty big values. More specifically, things like

P = C^d % n
  = 62^65 % 133

Now that is really the only calculations that ill be doing. I have tried using Matt McCutchen's BigInteger Library, but I am getting a lot of compiler errors during linking, such as:

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&)'

So I was wondering what would be the best way to go about handling the really big integers that come out of the RSA Algorithm.

I heard that a possibility would be to declare your variables as a double long, so...

long long decryptedCharacter;

but I'm not sure exactly how big of an integer that can store.


Well for example, I try to compile and run the following program using 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;
}

then I get those errors.

Derek, I thought that by including the BigIntegerLibrary.hh file, that the compiler would go through and compile all the necessary files that it will use.

How should I try and compile the program above in order to resolve the linking errors?

解决方案

Meta-answer:

If you're using a library for the bigint arithmetic, then ask yourself why you aren't using a library for the whole RSA implementation.

For example, http://www.gnu.org/software/gnu-crypto/ contains an RSA implementation. It has the same license as GMP.

However, they do not have the same license as http://mattmccutchen.net/bigint/, which appears to me to have been placed into the public domain in the US.

这篇关于C ++处理非常大的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆