A simple example for creating a vec_ZZ and vec_ZZ_p and their transformation in NTL

The codes

#include 
#include 
#include 
#include 
#define P 3
using namespace std;
int main() {
    // use the ntl create a vector and initialize it with {1, 2, 3}
    NTL::ZZ_p::init(NTL::ZZ(P));
    NTL::vec_ZZ_p v;
    v.SetLength(3);
    for (int i = 0; i < 3; i++) {
        v[i] = i + 1345643546;
    }
    NTL::ZZ_p x = NTL::conv<NTL::ZZ_p>(v[0]);
    NTL::vec_ZZ vv;
    vv.SetLength(3);
    for (int i = 0; i < 3; i++) {
        vv[i] = NTL::conv<NTL::ZZ>(v[i]);
    }
    NTL::vec_ZZ v2;
    v2.SetLength(3);
    for (int i = 0; i < 3; i++) {
        v2[i] = i + 5;
    }
    NTL::vec_ZZ v3;
    NTL::add(v3, vv, v2);
    // print the vector
    cout << "v3 = " << v3 << endl;
    return 0;
}

The compile command

g++ main.cpp -std=c++17 -lntl -lgmp

The results

v3 = [7 6 8]

你可能感兴趣的:(practice,for,C++,c++,算法,开发语言)