-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
119 lines (116 loc) · 4.28 KB
/
mainwindow.cpp
File metadata and controls
119 lines (116 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "sha256.h"
#include "MapEncrypt.h"
#include "RSA.h"
#include <sstream>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->SHA256, &QRadioButton::clicked, this, &MainWindow::onRadioButtonClicked);
connect(ui->MAP, &QRadioButton::clicked, this, &MainWindow::onRadioButtonClicked);
connect(ui->RSA, &QRadioButton::clicked, this, &MainWindow::onRadioButtonClicked);
connect(ui->DEMAP,&QRadioButton::clicked,this,&MainWindow::onRadioButtonClicked);
connect(ui->DERSA,&QRadioButton::clicked,this, &MainWindow::onRadioButtonClicked);
}
MainWindow::~MainWindow()
{
delete ui;
}
std::string SHA256_run(std::string word) {
sha256 words;
words.update(word);
return words.final();
}
//@detail 映射加密函数
std::string Encrypt_run(std::string word,int shift) {
MapEncrypt words(word, shift);
words.encrypt();
return words.show();
}
//@detail 映射函数解密
std::string decrypt_run(std::string word) {
MapEncrypt words(word,7);
words.decrypt();
return words.show();
}
//@detail RSA加密函数
std::string rsa_run(std::string plaintext) {
RSA rsa;
rsa.genKey(17, 19);
std::vector<int> ciphertext = rsa.encrypt(plaintext);
std::string res;
for (int num : ciphertext) {
res+=" "+std::to_string(num);
}
return res;
}
//RSA 解密函数
std::string de_rsa(const std::string& ciphertext_str) {
std::vector<int> ciphertext;
std::stringstream ss(ciphertext_str); // 使用stringstream来分割字符串
int num;
while (ss >> num) { // 从stringstream中按空格分割读取整数
ciphertext.push_back(num);
}
RSA rsa;
rsa.genKey(17, 19);
std::string decryptedText = rsa.decrypt(ciphertext);
return decryptedText;
}
void MainWindow::onRadioButtonClicked()
{
if (ui->SHA256->isChecked()) {
QString inputText = ui->lineEdit->text();
if (inputText.isEmpty()) {
ui->label->setText("你还没有输入任何内容哦,请输入后再点击提交。");
} else {
std::string input = inputText.toStdString();
QString res = QString::fromStdString(SHA256_run(input));
QString encryptedText = "SHA256加密结果: " + res;
ui->label->setText(encryptedText);
}
} else if (ui->MAP->isChecked()) {
QString inputText = ui->lineEdit->text();
if (inputText.isEmpty()) {
ui->label->setText("你还没有输入任何内容哦,请输入后再点击提交。");
} else {
std::string input = inputText.toStdString();
QString res = QString::fromStdString(Encrypt_run(input,7));
QString encryptedText = "MAP映射加密结果: " + res;
ui->label->setText(encryptedText);
}
} else if (ui->RSA->isChecked()) {
QString inputText = ui->lineEdit->text();
if (inputText.isEmpty()) {
ui->label->setText("你还没有输入任何内容哦,请输入后再点击提交。");
} else {
std::string input = inputText.toStdString();
QString res = QString::fromStdString(rsa_run(input));
QString encryptedText = "RSA加密结果: " + res;
ui->label->setText(encryptedText);
}
}else if(ui->DERSA->isChecked()){
QString ciperText = ui->lineEdit2->text();
if(ciperText.isEmpty()){
ui->label_2->setText("你还没有输入任何内容哦,请输入后再点击提交。");
}else{
std::string input = ciperText.toStdString();
QString res = QString::fromStdString(Encrypt_run(input,17));
QString plainText = "MAP解密结果: "+ res;
ui->label_2->setText(plainText);
}
}else if(ui->DEMAP->isChecked()){
QString ciperText = ui->lineEdit2->text();
if(ciperText.isEmpty()){
ui->label_2->setText("你还没有输入任何内容哦,请输入后再点击提交。");
}else{
std::string input = ciperText.toStdString();
QString res = QString::fromStdString(decrypt_run(input));
QString plainText = "MAP解密结果: "+ res;
ui->label_2->setText(plainText);
}
}
}