C ++大数字

问题描述 投票:0回答:1

我正在尝试为一个项目实施RSA,并且我陷入了需要大于19位数字(很长很长,我认为有19位数字)的阶段。我试着长时间给unsigned,但是我仍然没有1位数字,并且值不正确。我什至无法检查我的加密/解密是否有效。

我已经尝试了一些库,但是无法使用该类型和int进行交叉操作...有什么帮助吗?

这是我所拥有的:

void En() {
crypted= text;
unsigned long long temp=0;
unsigned long long enc = 0;
for (int i = 0; i < text.length() / 2; i++)
{
    if (text[i]>='a' && text[i] <= 'z')
    {
        temp = (text[i] - 96) * 26 + text[i + 1] - 96;
        enc = pow(temp, public_key);
        enc= enc % N
        cout << enc << endl;
        enc_v2 = enc;
    }

}

cout << "Enc: " << enc << endl;}

void De() {
unsigned long long c = 0;
unsigned long long temp2 = 0;
unsigned long long temp = 0;
char ch=' ', ch2=' ';
for (int i = 0; i < text.length()/2; i++)
{
    cout << enc_v2 << private_key;
    temp = pow(enc_v2, private_key);
    cout << "Temp :" << temp;
    temp = temp % N;
    cout << "Temp modulo :" << temp;
    temp2 = temp;
    temp = temp / 26;
    cout << " Temp char 1 :"<< temp;
    ch = temp + 96;


    temp2 = temp2 - temp * 26;
    cout << " Temp char 1 :" << temp2;
    ch2 = temp2 + 96;


}
cout << "Text: " << ch << ch2;}

谢谢!

c++ encryption rsa libraries biginteger
1个回答
0
投票

为了表示大于任何原始类型的整数,可以使用整数数组,其中数组的每个数字代表较大数字的不同字节。这称为任意精度算术。对于这种“大”数字类型,必须分别实现每个算术运算以及输入和输出。

© www.soinside.com 2019 - 2024. All rights reserved.