当前位置:网站首页>[密码学实验] 0x00 安装NTL库
[密码学实验] 0x00 安装NTL库
2022-07-29 07:53:00 【吉计小菜鸡】
这里用的是vs2022
编译NTL库
1.先创建静态库项目
2.将NTL包下src下所有文件添加到项目中工程右键->添加->现有项
选择所有文件
3.项目右击,属性C/C++->常规
源码包中include文件目录加到附加包含目录
;将SDL检查
设置为否C/C++->预编译头
不使用预编译头
(点击属性名称就可以改预设属性)
4.编译
VS顶部菜单栏生成->生成解决方案
编译完成后会生成lib文件
在项目目录下(这里我的项目名称是NTL_CPP)
复制下来这个路径,本次是E:\projects\test-project\NTL_CPP\x64\Debug
使用NTL库
现在创建一个要使用NTL库的项目
在要使用的项目右击选择属性
将源码包的Include文件夹路径添加到外部包含目录中,同时将SDL检查设置为否链接器->常规->附加库目录
添加.lib文件的路径
再把.lib文件名加到附加依赖项中
测试NTL库是否可使用
用一段RSA代码(来源是这位大佬的文章)测试,出现了error
#include<iostream>
#include<NTL/ZZ.h>
using namespace NTL;
int main(){
ZZ p, q, n, phi_of_n, public_key, private_key, message;
int no_of_bits;
std::cout<<"Enter no of bits : ";
std::cin>>no_of_bits;
// generating p and q prime numbers
p = GenPrime_ZZ(no_of_bits, 80);
q = GenPrime_ZZ(no_of_bits, 80);
n = p * q;
phi_of_n = (p-1)*(q-1);
ZZ i = (ZZ)1;
long bits_of_n = 0;
for( ; i <= n; i *= 10) {
bits_of_n++;
}
public_key = GenPrime_ZZ(bits_of_n/2, 80);
private_key = InvMod(public_key, phi_of_n);
std::cout<<"\nEnter Message to decrypt : ";
std::cin>>message;
// Encryption of message using public key
ZZ encrypted_message = PowerMod(message, public_key, n);
ZZ decrypted_message = PowerMod(encrypted_message, private_key, n);
std::cout<<"\np = "<<p<<"\n";
std::cout<<"\nq = "<<q<<"\n";
std::cout<<"\nn = "<<n<<"\n";
std::cout<<"\nphi of n = "<<phi_of_n<<"\n";
std::cout<<"\npublic key = "<<public_key<<"\n";
std::cout<<"\nprivate key = "<<private_key<<"\n";
std::cout<<"\nprivate key * public key (mod phi_of_n)= "<<MulMod(public_key, private_key, phi_of_n)<<"\n";
std::cout<<"\nEncrypted Message = "<<encrypted_message<<"\n";
std::cout<<"\nDecrypted Message = "<<decrypted_message<<"\n";
return 0;
}
4146,一波询问S同学发现是cpp文件里的SDL检查
改完后再运行一下,变成了warning,可以跑了
运行成功
边栏推荐
- Cfdiv1+2-bash and a high math puzzle- (gcd+ summary of segment tree single point interval maintenance)
- Use custom annotations to verify the size of the list
- Jump from mapper interface to mapping file XML in idea
- @Detailed explanation of requestmapping usage
- What are the principles and methods of implementing functional automation testing?
- Solve the problem that CSDN cannot publish blog due to unknown copyright
- MapReduce steps of each stage
- @JsonSerialize注解的使用
- Blue Bridge Cup group a selection XOR
- Gin abort cannot prevent subsequent code problems
猜你喜欢
Up sampling deconvolution operation
RoBERTa:A Robustly Optimized BERT Pretraining Approach
[cryoEM] Introduction to FSC, Fourier shell correlation
黑盒测试常见错误类型说明及解决方法有哪些?
Realize the effect of changing some colors of a paragraph of text
Ionicons icon Encyclopedia
Effective learning of medical image segmentation annotation based on noise pseudo tags and adversarial learning
QT connects two qslite databases and reports an error qsqlquery:: exec: database not open
LANDSCAPE
The new generation of public chain attacks the "Impossible Triangle"
随机推荐
Data unit: bit, byte, word, word length
[freeze electron microscope] analysis of the source code of the subtomogram alignment function of relion4.0 (for self use)
Output 1234 three digits without repetition
[introduction to cryoelectron microscopy] Caltech open class course notes part 3:image formation
Jianmu continuous integration platform v2.5.2 release
[cryoEM] Introduction to FSC, Fourier shell correlation
Technology sharing | quick intercom integrated dispatching system
Prepare esp32 environment
Getting started with JDBC
Go, how to become a gopher, and find work related to go language in 7 days, Part 1
The difference between static library and dynamic library of program
Phased learning about the entry-level application of SQL Server statements - necessary for job hunting (I)
Gin abort cannot prevent subsequent code problems
EF core reading text type is slow_ EF core is slow to read large string fields
Credit card shopping points
207.课程表
Access数据库引入datagridview数据后,显示错误
Database persistence +jdbc database connection
330. Complete the array as required
Effective learning of medical image segmentation annotation based on noise pseudo tags and adversarial learning