安装

首先去官网下载安装包,下列shell脚本与安装包放到同一目录,赋予此脚本执行权限。另外,我这里默认你的电脑上面已经安装gcc,g++,make。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#apt install -y gcc
#apt install -y g++
#apt install -y make
apt install -y autoconf

apt install -y m4
apt install -y libgmp-dev
apt install -y libgf2x-dev

tar zxvf ntl-11.4.3.tar.gz

mv ntl-11.4.3 ntl

echo -e "\033[31m start install ntl \033[0m"
cd ntl/src
./configure NTL_GF2X_LIB=on
make && make check && make install
cd - >> /dev/null

rm -r ntl

测试

新建一个rand.cpp(顾名思义,是输出随机数)

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <NTL/ZZ.h>
#include <time.h>
NTL_CLIENT
int main()
{
ZZ a,b,c;
SetSeed(to_ZZ(time(NULL)));
RandomLen(a, 32);
RandomLen(b, 32);
c = a + b;
cout << "a=" << a << ", b=" << b << ", c=" << c << "\n";
return 0;
}

按照官网的介绍,使用如下命令编译:

1
g++ -g -O2 -std=c++11 -pthread -march=native rand.cpp -o rand -lntl -lgmp -lm

其中rand.cpp是c++文件,rand是编译后的可执行文件。程序运行效果如下:
1
2
$ ./rand
a=2298665095, b=3622090486, c=5920755581

参考链接
NTL库快速上手中文指南
A Tour of NTL