Пример #1
0
    RSAKeySet::RSAKeySet(int length) {
        BigInt* p;
        BigInt* q;
        BigInt n;
        BigInt fi;
        while (true) {
            p = createBigint(length / 2)->makePrime();
            q = createBigint(length / 2 + 1)->makePrime();
            if(*q == *p) {
                q->add(*ONE)->makePrime();
            }
            n = *p * *q;
            fi = (*p - *ONE) * (*q - *ONE);
            delete p;
            delete q;

            BigInt *check = new BigInt(n);
            if (*check->gcd(fi) == *ONE) {
                delete check;
                break;
            }
            delete check;
        }

        BigInt *e = createBigint(fi.getData()->size() - 1);

        {
            BigInt *temp = new BigInt(*e);
            while (*temp->gcd(fi) != *ONE) {
                e->add(*ONE);
                temp->copy(*e);
            }
            delete temp;
        }

        BigInt *d = new BigInt(*e);
        d->inverseMod(fi);

        assert(((*d * *e) % fi) == *ONE);

        BigInt *test = createBigint(length - 1);
        BigInt *testCopy = new BigInt(*test);
        
        test->powMod(*d,n)->powMod(*e,n);
        
        assert (*test == *testCopy);
        
        privateKey = new RSAKey(&n, d);
        publicKey = new RSAKey(&n, e);
    }
Пример #2
0
s32 main(int32 argc, char *argv[])
{
    int32 x = 5, y = 1;
    if (argc == 2)
    {
        x = atoi(argv[1]);
    } else if (argc == 3) {
        x = atoi(argv[1]);
        y = atoi(argv[2]);
    }

    init();
    
    bigint num;

    createBigint(&num, 1);
    bignumFactorial(&num, x);
    printBigint(&num);

    printf( LONG "\n", sumBigDigits(&num));

    return 0;
}