密码学原理【Crypto++ 实现】RSA加密

本文介绍如何使用Crypto++库实现RSA加密和解密功能。具体步骤包括从指定文件中读取1024位密钥及不超过1000位的明文,进行加密并保存为密文,再将密文读出并解密还原为明文。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Requirements

请用 Crypto++实现一 个程序,具有加密和解密两种功能。在用加密功能时,读出一个名为“key.txt” 的文件中的 1024 位的密钥,一个名为“plain.txt”的文件中的一段不超过 1000 位的明文,用 RSA 加密后,密文写入一个叫做“encrypted.txt”的文件。在用解密功能时,读出一个名为“key.txt”的文件中的 1024 位的密钥,一个名为 “encrypted.txt”的文件中的密文,用 RSA 解密后,密文写入一个叫做 “decrypted.txt”的文件。所有文件格式均为纯文本,密钥、明文、密文均用 二进制书写,形如“00111010…”。请提交全部源代码。

RSA_Encryption Description

key: 1024 bits from “key.txt”
plaintext: less than 1000 bits from “plain.txt”
ciphertext: “encrypted.txt”
Encryption: RSA
Description: RSA
recovered: “descrypted.txt”

Description

Organization

Source code

.
├── README.md
├── RSA.cpp
├── RSA_Gen.cpp
└── test

After executing ./test

Note:

  • “test” contents a series of commands to complie and execute.
  • Current user should own executable permissions on “test” (You may add sudo).
.
├── README.md
├── RSA
├── RSA.cpp
├── RSA_Gen
├── RSA_Gen.cpp
├── d.txt
├── descrypted.txt
├── e.txt
├── encrypted.txt
├── key.txt
├── plain.txt
└── test

Here is an example:

86 bits saved in plain.txt
43 byte(s) Random String Generated Successfully in plain.txt
1024 bits saved in key.txt
1024 bits saved in d.txt
8 bits saved in e.txt
Plaintext is the following:
xxxx
Encryption Success. Ciphertext is the following:
xxxx
Ciphertext is the following:
xxxx
Descryption Success. Plaintext is the following:
xxxx

Source Code

需要的朋友请留言!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值